Skip to content

Instantly share code, notes, and snippets.

@rubyu
Last active November 29, 2017 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubyu/9167e2b52ab8033414fd70357079070e to your computer and use it in GitHub Desktop.
Save rubyu/9167e2b52ab8033414fd70357079070e to your computer and use it in GitHub Desktop.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe DisplayStandBy.cs
using System;
using System.Runtime.InteropServices;
namespace Monitor
{
class Power
{
const int HWND_BROADCAST = 0xffff;
const int WM_SYSCOMMAND = 0x0112;
const int SC_MONITORPOWER = 0xF170;
[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
static void Main()
{
System.Threading.Thread.Sleep(1000);
PowerOff();
}
static void PowerOff()
{
PostMessage((IntPtr)HWND_BROADCAST, WM_SYSCOMMAND, new IntPtr(SC_MONITORPOWER), new IntPtr(2));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment