How to lock your PC and turn off the display with one click

In Windows, you can lock your PC for security reasons using the Win + L shortcut. If you have not changed the default power management settings, the display will be turned off after 10 minutes. Windows does not provide a native way to turn off display directly on demand by running a command or pressing some button. If you are leaving your PC for a long time, you might want to lock your PC and turn off the monitor instantly with one click. It can be done via a simple script.


To make it working, we need to use the freeware tool, Nirsoft Nircmd, which allows you to control various OS parameters and features from the command line. Download NirCmd from here.

  1. Press the Win + R shortcut keys together on the keyboard to bring up the Run dialog, and then type notepad into the Run box.
    notepad
    Tip: see our ultimate list of all Windows keyboard shortcuts with Win keys.
  2. Copy and paste the following text into Notepad:
    'Lock PC and Turn off Display
    '*************************
    ' Created by Winaero
    ' https://winaero.com
    Dim WSHShell
    Set WSHShell=WScript.CreateObject("WScript.Shell")
    WSHShell.Run "Rundll32.exe user32.dll,LockWorkStation", 0
    WSHShell.Run "nircmd.exe monitor async_off", 0
    
  3. In Notepad, click File menu -> Save item. The 'Save as' dialog will appear. Browse for the desired folder where you wish to store the script and type "lock.vbs" with quotes in the 'File Name' text box (the double quotes are required so that the file gets directly saved as "lock.vbs" and not "lock.vbs.txt"):
    save as
  4. Put nircmd.exe you downloaded earlier in the same folder. You can also copy the NirCmd.exe into your C:\Windows directory. This is important so that all scripts can easily find its EXE.
    ready script

That's all. You are done. Now double click the 'lock.vbs' file. You PC will be locked and the screen will be turned off. You can use this trick in Windows XP, Vista, Windows 7 and Windows 8/8.1.

You can also pin this to your Taskbar using Taskbar Pinner or to your Start screen using Pin to 8 and then change its icon using this method.

2 thoughts on “How to lock your PC and turn off the display with one click

  1. Vaibhav

    Nice, I get help from this..

    Reply
    1. Pinaki Adhikary

      The monitor is getting into Power Saving mode but not in Turn off .

      Reply

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.