You are here

Windows: Turn off all your monitors via the command line

Submitted by Druss on Wed, 2021-11-24 19:26
  1. Create a batch file named turnoff.bat on your desktop.
  2. Open it and add the following line
    powershell (Add-Type '[DllImport("user32.dll")]^public static extern int PostMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::PostMessage(-1,0x0112,0xF170,2)
  3. Save the batch file.
  4. Run the file to turn off your screens.There will be a brief command-line window that pops up during execution.

Tested on Windows 10.

If you want to keep things quieter, you can also consider prefixing the command with an "@" which will ensure that the command is not displayed in the command-line window. If you don't want to command-line window to pop-up, then you can only create a shortcut to your batch file and then go to the shortcut's properties and run it in a minimised window. Note that the window will still appear in the task bar.

Hope this helps!