How to manually trigger "turn off display"? [duplicate]

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.


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.


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