Turning Display Off Immediately

by Jun 6, 2018

If you are about to launch a lengthy automation script, why not turn off the display right away instead of waiting for the screen saver timeout to kick in?

Here is a simple function that turns off your display immediately. Just move the mouse or press a key to turn it back on:

function Set-DisplayOff
    $code = @"
using System;
using System.Runtime.InteropServices;
public class API
  public static extern
  int SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
    $t = Add-Type -TypeDefinition $code -PassThru
    $t::SendMessage(0xffff, 0x0112, 0xf170, 2)

Twitter This Tip! ReTweet this Tip!