In Python 3, how can I tell if Windows is locked?

后端 未结 8 752
小鲜肉
小鲜肉 2021-01-13 11:27

How can I check whether a Windows OS workstation is locked? (e.g. Win+L or choosing the lock option after Ctrl+Alt+Del.)

I want something like ctypes.windll.us

8条回答
  •  萌比男神i
    2021-01-13 12:21

    A hacky I discovered to get around to see if Windows 10 is locked is to look at the running processes using psutil. You then search to see if LogonUI.exe is running. This process only runs if there when a user has a locked session.

    Note: If you use switch users this process will show as running and this workaround will not work. Windows actually spawns multiple LogonUI.exe processes, one per logged on locked user. It is only useful where only one person is logged on at a time.

    import psutil
    
    for proc in psutil.process_iter():
        if(proc.name() == "LogonUI.exe"):
            print ("Locked")
    

提交回复
热议问题