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.

user1306322
  • 4,866

4 Answers4

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.

stderr
  • 10,569
  • 2
  • 36
  • 50
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
VL-80
  • 4,693
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

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”.