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!

No Data
  • OK, from a pure risk management perspective. Why just blank the display and leaving the computer logged on potentially running code using a highly privilege account that someone can just walk up and well, you know. Why not lock the system instead with this native Windows OS one-liner in your script.

        C:\Windows\System32\rundll32.exe User32.dll,LockWorkStation

    Of course, one could wrap that in a function as well.

No Data