We help IT Professionals succeed at work.

powershell script to detect when user has locked display/screen

milesri
milesri asked
on
I need to be able to determine if user has locked the screen.   Is there a way to do this with powershell?
Comment
Watch Question

"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
Just throwing in some ideas:

According to http://www.microsoft.com/technet/scriptcenter/resources/qanda/nov04/hey1115.mspx there seems to be no foolproof way to determine if the screen is locked, but you can test for the screensafer's executable running, as shown at the bottom. However, that sounds clumsy.

http://stackoverflow.com/questions/248186/service-needs-to-detect-if-workstation-is-locked-and-screen-saver-is-active presents a solution in C#, which registers for the OnSessionChange event triggered when the session is switched, locked or unlocked. PowerShell can use C# code, but since we need to register for the event, the script would be required to run permanently, and record the current state itself.