Solved

Service notification for logon?

Posted on 1998-06-30
5
350 Views
Last Modified: 2013-12-03
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?
0
Comment
Question by:dmetzler
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
Musashi earned 200 total points
ID: 1409034
The service must have a (hidden) window which is looking for the WM_USERCHANGED message which is generated at logon & logoff.  

To interact with the user at logon, the service has to open the user's window station (via OpenWindowStation() for station "WinSta0") and desktop (via OpenDesktop() for Desktop "Default", or OpenInputDesktop()).
0
 

Author Comment

by:dmetzler
ID: 1409035
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
0
 
LVL 1

Expert Comment

by:Musashi
ID: 1409036
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.


0
 

Author Comment

by:dmetzler
ID: 1409037
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
0
 
LVL 1

Expert Comment

by:Musashi
ID: 1409038
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
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now