15

How do I manually trigger the "turn off display" function in Windows 7? This normally happens automatically when the user doesn't move mouse or presses any keys for a certain amount of time (power management section of control panel).

Third party software or a full blown application is nice, but I'd prefer an approach native to Windows 7. Like a command line or something.

1

4 Answers 4

11

This script written in Powershell can make this work for you.

# Turn display off by calling WindowsAPI.

# SendMessage(HWND_BROADCAST,WM_SYSCOMMAND, SC_MONITORPOWER, POWER_OFF)
# HWND_BROADCAST  0xffff
# WM_SYSCOMMAND   0x0112
# SC_MONITORPOWER 0xf170
# POWER_OFF       0x0002

Add-Type -TypeDefinition '
using System;
using System.Runtime.InteropServices;

namespace Utilities {
   public static class Display
   {
      [DllImport("user32.dll", CharSet = CharSet.Auto)]
      private static extern IntPtr SendMessage(
         IntPtr hWnd,
         UInt32 Msg,
         IntPtr wParam,
         IntPtr lParam
      );

      public static void PowerOff ()
      {
         SendMessage(
            (IntPtr)0xffff, // HWND_BROADCAST
            0x0112,         // WM_SYSCOMMAND
            (IntPtr)0xf170, // SC_MONITORPOWER
            (IntPtr)0x0002  // POWER_OFF
         );
      }
   }
}
'

[Utilities.Display]::PowerOff()

Note: This tip requires PowerShell 2.0 or above.

4
  • @user1306322 Correct. Screen saver does not turn off the display.
    – lance
    Dec 19, 2014 at 6:32
  • @user1306322 The answer has been updated.
    – stderr
    Dec 19, 2014 at 10:53
  • For the lack of a better answer I'm accepting this one. It should be noted that this is only useful when you are not interacting with the computer. That is, in order to make the screen stay powered off, you need to stop touching any buttons or mouse. Setting up a timer for a second or two before executing this command might be of great use. Dec 19, 2014 at 15:31
  • Setting this in a .bat file and double clicking does not work. Either the API has changed or either I don't know how to execute this. What's the "launch" method expected for this script? Mar 23, 2020 at 1:01
8

Not native solution - requires free external program Nircmd. But it is pretty useful and takes nothing to use it.

To turn monitor off:

nircmd.exe monitor off

To turn monitor on:

nircmd.exe monitor on
7

I use the Monitor Off Utility for several years. I assigned a shortcut combination and press it if I like to disable the display.

enter image description here

enter image description here

3
  • Not sure why the answer was downvoted. Neutralizing the effect since the utility does what OP wants
    – Ejaz
    Dec 31, 2015 at 21:04
  • Isn't really this kind of software doing something some command could do? No command to edit the turn off timer?
    – Andrestand
    Jul 20, 2017 at 11:50
  • @Andrestand the accepted answer shows you which API is used internally by the tool. Jul 20, 2017 at 14:39
0

Try

%SystemRoot%\System32\RUNDLL32 %SystemRoot%\System32\USER32.DLL,LockWorkStation

You may need to go into Control Panel and configure your screen saver to be “none”.

2
  • This only does what the LockWorkStation command name suggests − locks current user's session. The same effect can be achieved by pressing [Win]+[L]. Aug 13, 2013 at 0:40
  • Did what it said, turned off screen saver and then screen turns off automatically. Great. Mar 31, 2021 at 12:16

Not the answer you're looking for? Browse other questions tagged .