Reputation: 155
How to detect Windows is locked (Win+L or locked by screensaver)? Is it possible?
Upvotes: 8
Views: 5081
Reputation: 11
WTSRegisterSessionNotification() will require the elevated privileges on Windows 10/11.
Call WTSQuerySessionInformation with WTS_INFO_CLASS set to WTSSessionInfoEx.
struct _WTSINFOEX_LEVEL1_A has a member, LONG SessionFlags, which indicates whether the calling session is locked or not.
Upvotes: 1
Reputation: 941465
There is no documented way to check if the session is locked. There is however a way to detect that the session is getting locked. Use WTSRegisterSessionNotification(), you'll get a WM_WTSSESSION_CHANGE message with the WTS_SESSION_LOCK value when the workstation is being locked.
If you are planning to do this from a service then be sure to google "session 0 isolation" to find out why that doesn't work.
Upvotes: 14