Automatic Logoff

Hi all…

Does anyone know of a template or embeds to automatically log someone off a CW app
after a period of inactivity? I need to update some apps once in a while,
but everybody stays logged on and makes it very difficult. Having a way to
have them “drop off” automatically would be a great help.
Thanks for any help.


Look at: AutoCloseServer:

See the IDLE command in the language reference

Ok… pbouma & Mark thank’s…

As I understand, the requirement is to log people out or kill the application if there was inactivity for a stipulated period.
Just to check IDLE, I created a test app with an IDLE(Procedure,5) in program setup. This gets called every 5 seconds even though I was moving my mouse. Therefore, I think IDLE itself might not be sufficient.

I had a similar requirement to log off user based on user inactivity. I did that using window API calls:

GetTickCount or GetTickCount64

The GetLastInputInfo returns the last time there was a user activity on the PC.

Global Data
dwTime ULONG

Inside Global Map

NOTE: GetLastInputInfo(LONG), where long is ADDRESS(LIF).

You could call these procedures in your IDLE procedure to detect last user activity take actions accordingly

Inactivity Timeout is one of many features in our Super Security templates. You can get more info here: It’s also smart enough not to timeout while running long tasks like Reports.

Mike Hanson

Well, it depends on the environment. On a terminal server, I set everyone’s session to 20 minutes of idle time. Windows will end their session after 20 minutes of being idle. I don’t have to do anything in the program.
Then again, if the requirement is not to automatically log someone off but to be able to update an app, then all you need to do is rename the exe and put the updated app in its place. Users can continue working (or stay idle) and you can go home. I do this several times some days with 100’s of active users. (Of course this won’t work very well if you are changing any file definitions).

I was able to do this using GetLastInputInfo API but it works for the whole OS not just for current app.

Anyone know how to get inactivity for my Application only (per “my application instance”)???

I’m curious to know whey your update requires users to log off. Is it because you need to change the database, or replace the EXE?


I have a site that uses a MS SQL database and MS Access clients. The client “knows” its current version, and checks this in a Version table on the server whenever the user starts the program. If they differ then it exits and runs a batch file to copy the new client code to the workstation.

If I need to update the data structure it’s easy enough to add new fields, or even increase the field size, but deleting a field becomes more of a problem. In that case it is best to prepare the new code file and update the clients before removing the field from the live database.

Most of the updates are done outside normal office hours, so I have a background routine that will automatically quit the program after 11pm, to cater for people who leave work without closing the program.

Perhaps instead of checking for user inactivity, you could do a regular check for a new program version, and then ask the user to exit? The ask dialog could have a timer to answer “Yes” by default if the user doesn’t respond after a few minutes.

I’ve got a timer event on my app frame. Every few seconds I check a flag on the database and if set, a waning is displayed and shuts the program down. All you need to do then is set the flag, wait a minute and everyone is out. The program check the flag on startup and won’t start till the flag is reset.


I have used the same technique as Bertus, but added a feature where I can remotely set to close down and prevent opening from an administrators’ program. That allows us to close everyone down, deploy an upgrade, then reset to allow opening again. We can then do a minor upgrade as long as database changes are minimal very quickly (3-5 min) during working hours. Obviously any larger database alterations still get have to be done outside busy working hours.

The CleanCloseDown templates support this really well (see Clarion help pages)

Regards, Jim

1 Like