Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Service notification for logon?

Posted on 1998-06-30
5
Medium Priority
?
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
Musashi earned 800 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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