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

How to Use CMD Command to Lock Computer

You can lock Windows computer directly from the Command Prompt. Here’s the CMD command you should use to lock the computer.

Windows offers a wide range of ways to lock the PC. For example, you can simply press the “Windows Key + L” keyboard shortcut to lock your computer. Alternatively, you can also create a dedicated desktop shortcut to lock the PC. But did you know that you can lock PC from Command Prompt?

Sure, using the Command Prompt is not the most intuitive or easiest way. But, knowing how to do it is very helpful in a lot of ways. For example, if you are creating a custom command-line script or to lock the PC on schedule, you have to execute the lock PC command. After all, it is tough to simulate keystrokes in a script or scheduled task. The good thing is, the command to lock the computer is pretty simple and easy to execute.

Follow the steps below to learn how to use a CMD command to lock the computer via the Command Prompt.

Command to lock Windows computer

To use a CMD command to lock a Windows computer, follow the steps listed below.

1. Open the Start menu. You can do that by pressing the “Windows logo” key on your keyboard. In the start menu type “CMD”. This will show the Command Prompt result at the top. Click on it to open the Command Prompt window.

2. After opening the Command Prompt window, you can execute the command to lock the computer. To do that, copy the below command, paste it in the Command Prompt window and press the “Enter” button.

A quick tip: to paste the command in the Command Prompt window, simply right-click in the window. Of course, you can also use the Ctrl + V or Ctrl + Shift + V.

Rundll32.exe user32.dll,LockWorkStation

Cmd-command-to-lock-computer-261120

As soon as you complete the above command, the computer will be locked. To unlock the system, you need to provide the pin or password on the login screen.

Set computer lock Timer in command prompt

If you want to, you can also command Windows to lock automatically using a lock timer. To do this you have to execute a command with the amount of time in seconds after which the computer should lock. Here’s how to do it.

1. First, open the command window. You can do that by searching for “Command Prompt” in the Start menu.

2. In the command line window, copy and paste the below command. Replace “<LOCKTIMER>” with the amount of time in seconds after which the computer should be locked.

powercfg.exe /SETACVALUEINDEX SCHEME_CURRENT SUB_VIDEO VIDEOCONLOCK <LOCKTIMER>

Important Note: If you are using a laptop running on battery (i.e, not on AC power), you need to execute the below command. If you look carefully at the command, all we did was replace “/SETACVALUEINDEX” with “/SETDCVALUEINDEX”.

powercfg.exe /SETDCVALUEINDEX SCHEME_CURRENT SUB_VIDEO VIDEOCONLOCK <LOCKTIMER>

3. Press the “Enter” key to execute the command. In my case, I want to lock the system after 1 hour. So, I entered 3600 seconds in the command.

4. After configuring the lock timer, you need to activate it. To do that, execute this command.

powercfg.exe /SETACTIVE SCHEME_CURRENT

5. Finally, close the Command Prompt window.

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

I hope that helps. If you are stuck or need some help, comment below and I will try to help as much as possible. If you like this article, check out how to create lock computer desktop shortcut.

Leave a Comment

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

Scroll to Top