Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [CmdletBinding()]
- param(
- [Parameter(Mandatory=$false)][switch]$PowerOn
- )
- # 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
- );
- }
- public static void PowerOn ()
- {
- SendMessage(
- (IntPtr)0xffff, // HWND_BROADCAST
- 0x0112, // WM_SYSCOMMAND
- (IntPtr)0xf170, // SC_MONITORPOWER
- (IntPtr)(-0x0001) // POWER_ON
- );
- }
- }
- }
- '
- Start-Sleep 5
- if($PowerOn) {
- [Utilities.Display]::PowerOn()
- } else {
- [Utilities.Display]::PowerOff()
- }
Advertisement
Add Comment
Please, Sign In to add comment