Solved

Service notification for logon?

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run Program using VBScript 3 79
Vb.Net Loading Word 11 107
T-SQL Debugging - Temp Object Content 2 55
Why I am having this error installing Visual Basic Enterprise 11 66
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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 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