Lock Your Workstation from the Command Line (rundll32)
The classic user32.dll,LockWorkStation rundll32 trick locks Windows instantly — no GUI needed.
Run rundll32.exe user32.dll,LockWorkStation to lock the current session immediately.
01Command
Command
$ rundll32.exe user32.dll,LockWorkStation02What it does
This calls the Win32 LockWorkStation API, the same one Win+L triggers, so the session is secured with your normal sign-in method. It is ideal for shortcuts, scheduled tasks (auto-lock after idle without a screen saver), or the end of a script that performed admin work. Note rundll32 is only meant for this small set of hand-written entry points — LockWorkStation is one of the legitimate ones.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Rundll32 - Run a DLL commandEvidence: Documents the rundll32 user32.dll,LockWorkStation entry point for locking the workstation from a command line or shortcut.
- LockWorkStation function (winuser.h)Evidence: Documents the LockWorkStation API that rundll32 invokes: it locks the workstation's display, requiring the caller to unlock normally.
Last verified: 2026-09-17 · Category: Security & Privacy