使用Python锁定Windows工作站

Thi*_*ter 11 python windows

有没有办法从Windows上的Python脚本锁定PC?

我不想自己实现某种锁定 - 我想使用当用户通过开始菜单按下WIN+ L或锁定机器时也使用的锁屏.

Thi*_*ter 23

这可以通过user32.dll中LockWorkStation()函数完成:

此功能与按Ctrl + Alt + Del并单击"锁定工作站"的结果相同.

在Python中,可以使用Python stdlib中的ctypes/windll FFI调用它:

import ctypes
ctypes.windll.user32.LockWorkStation()
Run Code Online (Sandbox Code Playgroud)