6
votes

How to detect Windows is locked (Win+L or locked by screensaver)? Is it possible?

1
This is an old question, but there are new answer: For windows 7 and abowe WTS API can be usedOleg Korzhukov

1 Answers

11
votes

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.