Locking your computer via command line provides efficiency and automation benefits. Follow these reliable methods applicable to modern Windows systems.
Method 1: Using Rundll32 (All Windows Versions)
- Open Command Prompt: Press Win+R, type "cmd", then press Enter.
- Execute command: Type * *,LockWorkStation
- Confirm: Your computer locks instantly. Close the command window.
Method 2: PowerShell (Windows 8/10/11)
- Launch PowerShell: Press Win+X, select "Windows PowerShell".
- Run command: Enter powershell -command "& {Add-Type -MemberDefinition '[DllImport("*")] public static extern void LockWorkStation();' -Name Win32Lock -Namespace System; [*32Lock]::LockWorkStation()}"
- Result: System locks immediately upon execution.
Creating Quick-Access Shortcuts
- Right-click desktop → New → Shortcut
- For CMD method: Paste * *,LockWorkStation in location field
- For PowerShell: Paste the full PowerShell command string
- Name shortcut (e.g., "Instant Lock") → Double-click to execute
Advanced Automation Options
- Schedule locking with Task Scheduler using rundll32 as action
- Bind command to keyboard shortcuts via third-party tools
- Include in logoff scripts for automated session locking
Both methods require administrative privileges only for creating persistent shortcuts. Execution works under standard user accounts. Verify system security policies allow workstation locking if encountering issues.