Created
September 26, 2015 21:21
-
-
Save prasannavl/835ce9882a9357487df4 to your computer and use it in GitHub Desktop.
Powershell script to turn display off
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 PVL { | |
public static partial class WindowsAPI | |
{ | |
[DllImport("user32.dll", CharSet = CharSet.Auto)] | |
public static extern IntPtr PostMessage( | |
IntPtr hWnd, | |
UInt32 Msg, | |
IntPtr wParam, | |
IntPtr lParam | |
); | |
} | |
public static partial class Utility | |
{ | |
public static partial class Display | |
{ | |
public static void PowerOff () | |
{ | |
WindowsAPI.PostMessage( | |
(IntPtr)0xffff, // HWND_BROADCAST | |
0x0112, // WM_SYSCOMMAND | |
(IntPtr)0xf170, // SC_MONITORPOWER | |
(IntPtr)0x0002 // POWER_OFF | |
); | |
} | |
} | |
} | |
} | |
' | |
function Set-DisplayOff { | |
[PVL.Utility+Display]::PowerOff(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi can you please make opposite of this script,
i am currently using this script to turn off the monitor (task scheduler) @ 5:01pm
and have another script to reboot machine at (task scheduler) @8:59am - shutdown /r
this computer does not have keyboard or mouse attached thats why need an script
Thank you