1 class Program 2 { 3 private const uint WM_SYSCOMMAND = 0x112; //系统消息 4 private const int SC_MONITORPOWER = 0xF170; //关闭显示器的系统命令 5 private const int MonitorPowerOff = 2; //2为PowerOff, 1为省电状态,-1为开机 6 private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);//广播消息,所有顶级窗体都会接收 7 8 [DllImport("user32.dll")] 9 private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); 10 static void Main(string[] args) 11 { 12 SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, MonitorPowerOff); 13 } 14 15 }