How do I know if a user is logged in (Windows 2000 and newer)?

It is necessary to find out in the Win-service that the user has logged in interactively. Get some notice or something else. What are some ways to find out?

    2 answers 2

    Variants.

    1. For Windows 2000, XP, 2003 - create a Winlogon notification package.
    2. For Windows Vista, 7 — subscribe to the SENSE system messaging service.

    Another API for the remote desktop contains the WM_WTSSESSION_CHANGE notification. And it is possible that the WMI class Win32_LogonSession may contain the necessary events.

    • Thank you, subscription to Sense messages helped. And it works in all systems, not only in Vista & Seven. - IAZ

    There are scripts that are executed when you log on to the system - look in the local security policy.

    • So what, what are they? Your answer is not clear. - IAZ
    • Well, this is a way to tell your program that the user is logged in. But how it should interact with your program is to invent it. You want - you can leave the file in any folder. - Sergey
    • Running a file, a script ... when logging in to the system is not an option, because you need a moment of entry, and not the end of the desktop initialization. Moreover, it is not reliable, because the user can delete this file, the script ... and it will not start. - IAZ
    • There is a Run branch in the registry and many more places where you can run the script. - Sergey
    • Dear gecube, can I find out the reason for the minus? - Sergey