Link to home
Start Free TrialLog in
Avatar of dmetzler
dmetzler

asked on

Service notification for logon?

I have a Win32 app running as a service in Win95/NT.  I would like my application to be notified when a user logs on the workstation.  How can I do this?
ASKER CERTIFIED SOLUTION
Avatar of Musashi
Musashi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dmetzler
dmetzler

ASKER

Thanks.  I can now determine a logon/logoff change, but how do I know what state the program is in at any time?

If the process is started as a service before logon and I get a WM_USERCHANGED message, I know I am logged in.  If a user logs off (ie program is started via command-line) I know the user is logged off.  But how do I know what state the program is in when it starts?

Thanks,

Don
Thank you for the nice grade!

Not sure I understand enough about your service to answer the question.  Please check out the following & provide as much info as possible:

1)Is the service a regular application that can also be installed as a service with the help of another program(eg, SRVANY.exe)?  If so, a call to WNetGetUser() should either fail if run as a service (or if it somehow succeeds will return the user name as "SYSTEM"), or succeed (with user name other than "SYSTEM") when started (run) via command line.

2) Is it a pure service and by "started via command-line", you mean it is installed as a service (manual) and then started with SC.exe or Net.exe (or Control Panel) or some other similar service controller?  If this is the case, is it SERVICE_SYSTEM_START or SERVICE_AUTO_START, vs. SERVICE_DEMAND_START?  If Demand_start, you could make it Auto_start and always be keeping track of wm_userchanged, even when it is reporting that it is paused or stopped.


It can be run as a service (by entering a service entry in the registry) or it can be run after logged in.

In the latter, a user can log off and still have the application running - this currently works.

It sounds like using WNetGetUser() will let me determine what state the workstation is in.  Does this work in 95/98/NT (or require dynamic linking)?

Thanks,

Don
WNetGetUser() doc says NT 3.1 or later, and Windows 95 or later.
It is declared in winnetwk.h and requires linking with mpr.lib, no dll's are mentioned.

Good luck,

Bob