Results 1 to 3 of 3

Thread: Determining the active user

  1. #1

    Thread Starter
    Lively Member bren0098's Avatar
    Join Date
    Jul 2005
    Posts
    67

    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.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Last edited by LaVolpe; Feb 16th, 2010 at 04:41 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Lively Member bren0098's Avatar
    Join Date
    Jul 2005
    Posts
    67

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width