Determining the active user
Hello all,
Does anyone know how to determine if the current user that is logged on is the current user running the application?
For example:
A) User A logs on. Program runs.
B) User A decides to use XP's fast user switching. (remains logged on)
C) User B logs on. Program runs. I want User A's program to pause.
D) User A logs on. User B is now paused.
Any help appreciated.
Re: Determining the active user
I think the WTSRegisterSessionNotification API is your answer. It will require subclassing of whatever hWnd you pass to it. The subclassed message will be WM_WTSSESSION_CHANGE and finally, you must also unregister the service with a call to the WTSUnRegisterSessionNotification API
Code:
Private Const WM_WTSSESSION_CHANGE As Long = &H2B1&
I have never used those APIs and am not 100% sure it is what you need, but it would be easy enough to test.
From what I read on the links, this won't tell you who the active user is because in the XP session, the user doesn't change. But it should tell you when the user is switching back and forth.
Edited: Using the API and monitoring the message along with its content (see the links above), your logic looks like:
A) User A logs on. Program runs. Start service with call to WTSRegisterSessionNotification
B) User A decides to use XP's fast user switching. (remains logged on)
C) User B logs on. Subclassed message received in program A: Pause User A
Program runs for User B. Start service with call to WTSRegisterSessionNotification
D) User A logs on. Subclassed message received in program B: Pause User B
Subclassed message received in Program A, unpause User A
E) When application A and/or B closes, unregister service with call to WTSUnRegisterSessionNotification
Searching the forums provided an example
Re: Determining the active user
Thanks LaVolpe, this is what I am looking for, however when User A logs off, the program is paused, and when User B logs on, User A's program becomes unpaused and User B's program continues to run as normal...