Lock windows workstation using Python

后端 未结 2 1531
甜味超标
甜味超标 2020-12-09 11:20

Is there a way to lock the PC from a Python script on Windows?

I do not want to implement some kind of locking on my own - I\'d like to use the same lock screen that

2条回答
  •  不思量自难忘°
    2020-12-09 11:35

    This can be done with the LockWorkStation() function from user32.dll:

    This function has the same result as pressing Ctrl+Alt+Del and clicking Lock Workstation.

    In Python it can be called using using the ctypes/windll FFI from the Python stdlib:

    import ctypes
    ctypes.windll.user32.LockWorkStation()
    

提交回复
热议问题