Auto logoff

P

PawelR

Hello Group,
To my apps user must logon.
How make auto logoff after any time when user is not active?

Please send me samples or link to samples.
Thx.
Pawel
 
N

Nicholas Paldino [.NET/C# MVP]

Pawel,

Figuring out inactivity in an application is difficult, at best. What
you will want to do is probably hook into the applications main message loop
(by implementing the IMessageFilter interface and registering it on the
Application through the static AddMessageFilter method). In there, you
would look for any mouse movement messages, and any keystroke messages. You
would also have a timer which would be reset every time one of these
messages came in. If the timer ever fires (the timer would br set to fire
after your timeout period, for example, set the timer to fire every three
minutes if you want your application to quit after three minutes of
inactivity), then you know the app was inactive, and you can log out.

Hope this helps.
 
G

Girish Bharadwaj

Nicholas said:
Pawel,

Figuring out inactivity in an application is difficult, at best. What
you will want to do is probably hook into the applications main message loop
(by implementing the IMessageFilter interface and registering it on the
Application through the static AddMessageFilter method). In there, you
would look for any mouse movement messages, and any keystroke messages. You
would also have a timer which would be reset every time one of these
messages came in. If the timer ever fires (the timer would br set to fire
after your timeout period, for example, set the timer to fire every three
minutes if you want your application to quit after three minutes of
inactivity), then you know the app was inactive, and you can log out.

Hope this helps.
Or,..
You can write a screen saver.. Let windows take care of activating you
and when it does.. log off the user..
:)
 
N

Nicholas Paldino [.NET/C# MVP]

Girish,

That's a great hack! I mean, it is hackish, but its actually a great
mechanism. Here are the problems with that though:

- There is only one screen saver on the system, so you will eliminate
another one (which might be needed or desired)
- Is there a way from within the screen saver to indicate that it should
stop, or can you just exit the program?
 
G

Girish Bharadwaj

Nicholas said:
Girish,

That's a great hack! I mean, it is hackish, but its actually a great
mechanism. Here are the problems with that though:

- There is only one screen saver on the system, so you will eliminate
another one (which might be needed or desired)
- Is there a way from within the screen saver to indicate that it should
stop, or can you just exit the program?
Heheh.. I agree. Its a hack. :)
As for the two problems, if you agree that a Screen saver is the way to go..
For one, I would just write the "settings" for that saver to provide a
list of screen savers available and a time out on them as well. Of
course the idea now is that you will have two times one when the logoff
screensaver comes active and the *real* screen saver also becomes
active. And after a certain time out, the real screen saver is killed by
the logoff screen saver and logged off..
You can do that since its similar to one of those marquee screen savers..
or else,
the poster can write his own cool screen saver (a chance to play with
DirectX maybe).. :)

Seriously, I would expect a place where you need a auto logoff mechanism
to be deployed would not be too averse to having a screensaver set to
such a thing .. since this makes most sense in a kiosk kind of env and
there system admin is king.. :)
 
N

Nicholas Paldino [.NET/C# MVP]

Girish,

Even easier. When the screen saver is run, it posts a message of type
WM_SYSCOMMAND, where the wParam parameter is the value SC_SCREENSAVE. This
message can be processed if you set a hook using the SetWindowsHookEx
function which would filter the windows messages.

However, this still limits your timeout to whatever the screen saver is
set to, which is a pain.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top