Is knowing Screen lock status from UWP app possible?

Rahul K 51 Reputation points

When my Universal Windows Platform(UWP) app is open and user locked the screen i want to know that screen is locked i.e., status of the screen lock.

When the screen is locked the 'OnSuspending' method of App.xaml.cs will be fired. Now whatever the APIs are vailable to detect this screen lock, i want to use them and detect.



Can this lockscreen namespace be used to detect screenlock?


  • can we use 'Microsoft.Win32.SystemEvents.SessionSwitch' to detect lock screen ststus from UWP app?(as provided in 2nd link)
  • Is there any other possible way?
Universal Windows Platform (UWP)
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,362 questions
0 comments No comments
{count} votes

Accepted answer
  1. Roy Li - MSFT 29,306 Reputation points Microsoft Vendor


    Welcome to Microsoft Q&A.

    There is no native UWP API that could detect the Screen lock status. APIs in Windows.ApplicationModel.LockScreen Namespace is used to create Lock screen apps that will automatically show when the screen is locked. But it can't detect when the screen is locked.

    >>can we use 'Microsoft.Win32.SystemEvents.SessionSwitch' to detect lock screen status from UWP app?

    The answer is no. Please check the document for SystemEvents.SessionSwitch Event. At the end of the document, there is no UWP mentioned.

    >>Is there any other possible way?

    If you really need this, a possible way is to create a win32 app that uses SystemEvents.SessionSwitch Event to detect the lock screen status. After you could create a Windows Application Packaging Project and add both your UWP and the win32 app into it. Then you could use AppService to communicate between the UWP app and the Win32 app.

    You could refer to this document about how to add the win32 app into a Windows Application Packaging Project.

    For using AppService between UWP app and win32 app, you could open your favourite search engine and search for Stefan Wick's blog.

    Thank you.

0 additional answers

Sort by: Most helpful