There is no documented way to check if a session is locked. However, there is a way to detect that the session is being blocked. Use WTSRegisterSessionNotification (), you will receive a WM_WTSSESSION_CHANGE message with the value WTS_SESSION_LOCK when the workstation is locked.
If you plan to do this from a service, be sure to turn off βsession 0 sessionβ to find out why this is not working.
source share