Skip to content

Instantly share code, notes, and snippets.

@ksasao
Created November 5, 2017 13:52
Show Gist options
  • Save ksasao/4121c976d334144eab73625214ec5032 to your computer and use it in GitHub Desktop.
Save ksasao/4121c976d334144eab73625214ec5032 to your computer and use it in GitHub Desktop.
PCの画面をオフにする
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace DisplayPowerOff
{
/// <summary>
/// PCのディスプレイをOFFにする。
/// </summary>
class Program
{
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(int hWnd, uint Msg, int wParam, int lParam);
enum MonitorState
{
On = -1, Off = 2, StandBy = 1
}
public static void PowerOff()
{
SendMessage(-1, 0x112, 0xf170, (int)(MonitorState.Off));
}
static void Main(string[] args)
{
PowerOff();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment