I wanna write a program that should perform some tasks automatically if someone logs onto my server.
My questions regarding this are:
-
1) Is there a last login record that
is set right after a user logs in
that I can use/monitor for my
purpose? If not is there something
similar I can use? -
2) What’s the best way to constantly
monitor such a value?
Your best (and by far safest) bet is to create a service that accepts the SERVICE_CONTROL_SESSIONCHANGE control.
This will allow your service control handler to receive a control whenever a user logs on, logs off, locks the session, and various other options. Look for more info in a link blow.
This is done by creating a service which has the SERVICE_ACCEPT_SESSIONCHANGE flag in the dwControlsAccepted, as following:
Followed by:
This will allow windows to send SERVICE_CONTROL_SESSIONCHANGE controls to your HandlerEx function, which should look something like this:
You can read up on all the different session change notifications you can receive from here: WM_WTSSESSION_CHANGE, all the notifications you’ll need are in the wParam part of the description.
Well, that’s the gist of it anyway. You can read more info on the handlerex function here: HandlerEx and more information about services in general here: Service Functions. I suggest you read up on the ServiceMain function, RegisterServiceCtrlHandler function and, most importantly, read the examples posted on the MSDN pages. They’re super helpful.
Good luck!