question

RahulK-5396 avatar image
0 Votes"
RahulK-5396 asked ·

Is knowing Screen lock status from UWP app possible?

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.


checking-for-workstation-lock-unlock-change-with-c-sharp

windows.applicationmodel.lockscreen


Can this lockscreen namespace be used to detect screenlock?

how-to-get-windows-unlock-event-in-c-sharp-windows-application


  • 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?



windows-uwpwindows-wpfwindows-uwp-xamlwindows-desktop-bridge
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RoyLi-MSFT avatar image
0 Votes"
RoyLi-MSFT answered ·

Hello,

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.


· 2 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

Thanks for your answer.
so you mean to suggest to use 'appservice' to communicate between win32 and uwp. Is it something same like the answer i got for my stackoverflow question

61220775

DetectLockScreen


and the github sample provided in the answer of the above question is :
can we solve this issue by taking help of external c++ code like in the below links:

32115698


nf-winuser-lockworkstation


0 Votes 0 · ·

For the first question, yes, it's the same way as @Nico-MSFT said.
For the second question, the document for LockWorkStation function you provide shows the function is used to lock the WorkStation not detecting the lock status and this is for WorkStation. The SO link you shared shows a win32 solution and it could not be used in UWP apps. You might still need to use Desktop Bridge to call the win32 solution.

0 Votes 0 · ·