none
How to detect when user login or logout RRS feed

  • Question

  • Hi, I have an app published through Windows Store, using the Desktop Bridge.

    I would like to be able to detect when the user sign in to windows. In general I would like to know when the user lock or unlock the computer, and when the user login or logout from the computer.

    My app is running on windows startup using the Windows.ApplicationModel.StartupTask. I want to activate some things only when the user are logged in to windows and not when user is logged out or the computer is locked.

    How can I acheive this?

    It's a System.Windows.Forms.Form window application project using the Desktop Bridge.

    Wednesday, July 10, 2019 9:17 AM

Answers

  • Hi,

    Well, I'm sorry to say that currently there is no way to detect when the user login or logout using native UWP APIs. You might still need to using desktop APIs to implement this.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Jon 76 Thursday, July 11, 2019 7:03 PM
    Thursday, July 11, 2019 3:01 AM
    Moderator

All replies

  • Hi,

    Well, I'm sorry to say that currently there is no way to detect when the user login or logout using native UWP APIs. You might still need to using desktop APIs to implement this.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Jon 76 Thursday, July 11, 2019 7:03 PM
    Thursday, July 11, 2019 3:01 AM
    Moderator
  • Hi Roy, 

    thanks for the clear answer! I continued my search among the desktop APIs and found this working code:

    Microsoft.Win32.SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
    private static void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
    {
    if (e.Reason == SessionSwitchReason.SessionUnlock)
    {
    // Windows unlocked by user. Do something.
    }
    }
    Hope it helps someone!


    • Edited by Jon 76 Thursday, July 11, 2019 7:03 PM edit
    Thursday, July 11, 2019 7:03 PM