Skip to content

Instantly share code, notes, and snippets.

@GadgetSteve
Created October 22, 2024 04:20
Show Gist options
  • Save GadgetSteve/2f35f8425f40060c10c7181841a12bef to your computer and use it in GitHub Desktop.
Save GadgetSteve/2f35f8425f40060c10c7181841a12bef to your computer and use it in GitHub Desktop.
Detect if windows is locked
# coding: utf-8
"""
check_windows_locked.py
Copyright: (c) Steve Barnes 2024
Author: Steve Barnes <[email protected]>
Check if a windows system is screen locked.
"""
import sys
import time
import psutil
def screen_locked():
"""Check if screen locked."""
loc_proc_names = ["LogonUI.exe", ] # Use a list in case of future changes
for proc in psutil.process_iter():
if proc.name() in loc_proc_names:
return True
return False
if __name__ == "__main__":
print(
"Test of",
sys.argv[0],
"lock your screen & wait a couple of seconds",
"before unlocking",
)
for _ in range(10):
time.sleep(1)
print(time.asctime(), "LOCKED" if screen_locked() else "OPEN")
print("Done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment