Home » How To » How to Use CMD Command to Lock Computer

Use This Command To Lock Screen in Windows 11 & 10

Learn the command to instantly lock the screen or set a lock timer in Windows 11 and Windows 10.

On Windows, pressing the “Windows key + L” shortcut locks the screen instantly. To use your computer again, you need to authenticate with a password, PIN, or biometrics. But, what if you want to lock Windows using a command? For example, maybe you want to create a script to lock the system on specific events, create a scheduled task, or set a timer to lock the screen automatically. In my case, I used the below lock screen command to create a custom script that is automatically triggered on a specific event so that the system is automatically locked.

In this quick and simple guide, I’ll show you two useful commands. One to instantly lock your system, and another to set a timer that locks it automatically after a specified time. Let’s get started.

Command to Lock Screen Instantly in Windows 11 & 10

Here’s the command and how to use it to lock your screen instantly in Windows 11 and Windows 10.

  1. Open the Start menu by pressing the “Windows” key.
  2. Search for “Command Prompt“.
  3. Click the top result or the “Open” option.
  4. Run the following command to lock the screen instantly.
    Rundll32.exe user32.dll,LockWorkStation
  5. To log back in, use your PIN, passwords, or Windows Hello biometrics.

A quick tip: Rather than typing the command manually, you can copy it (Ctrl + C), paste it (Ctrl + V) in the Command Prompt window, and press “Enter”.

Good to read: How to create a desktop shortcut to lock screen

Cmd-command-to-lock-computer-261120

Command To Set a Timer To Lock Screen Automatically in Windows 11 & 10

Windows also has a command to lock your screen automatically after a set amount of time. For example, maybe you want to lock your computer after one hour. In that case, running the following command sets the timer, and once it is done, the system will be locked automatically. Here’s how:

  1. Open the Start menu by pressing the “Windows” key.
  2. Search for “Command Prompt” and click “Open“.
  3. Run the following command to set the timer while replacing “<LockTimerInSecs>” with the number of seconds you want to wait before locking the system.
    1. On desktops: powercfg.exe /SETACVALUEINDEX SCHEME_CURRENT SUB_VIDEO VIDEOCONLOCK <LockTimerInSecs>
    2. On laptops: powercfg.exe /SETDCVALUEINDEX SCHEME_CURRENT SUB_VIDEO VIDEOCONLOCK <LockTimerInSecs>
  4. Next, run the following command to activate the timer.
    powercfg.exe /SETACTIVE SCHEME_CURRENT
  5. That’s it. Once the timer is done, Windows will lock itself automatically.

From now on, Windows will count down the lock timer and lock the PC after the timeout. Once locked, you can log back in from the lock screen using your PIN or password.

As you can see, whether you want to lock the screen instantly or after a specified time, Windows has two easy commands to get it done. In general, most of us only ever need the first command, which locks the system instantly. However, if you want Windows to lock itself after a specified time, use the second command.

If you have any questions or need help, comment below. I’ll be happy to assist.

Leave a Comment

Your email address will not be published. Required fields are marked *