Solved

Service notification for logon?

Posted on 1998-06-30
5
357 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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