用命令行锁定电脑(rundll32 LockWorkStation)
经典的 rundll32 user32.dll,LockWorkStation 技巧可立即锁定 Windows,无需任何图形界面。
运行 rundll32.exe user32.dll,LockWorkStation 即可立即锁定当前会话。
01命令
命令
$ rundll32.exe user32.dll,LockWorkStation02作用说明
这条命令调用的是 Win32 的 LockWorkStation API,与 Win+L 快捷键触发的是同一个函数,锁屏后使用正常的登录方式解锁即可。它非常适合放在快捷方式、计划任务中(在无屏保的情况下空闲后自动锁屏),或放在执行完管理员操作的脚本末尾。rundll32 只适用于少数手工编写的入口点,LockWorkStation 正是其中合法的一个。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- Rundll32 - Run a DLL command依据: Documents the rundll32 user32.dll,LockWorkStation entry point for locking the workstation from a command line or shortcut.
- LockWorkStation function (winuser.h)依据: Documents the LockWorkStation API that rundll32 invokes: it locks the workstation's display, requiring the caller to unlock normally.
最后验证: 2026-09-17 · 分类: 安全与隐私