1、黑屏API
static class Program { static SqlConnection connection; private const int WM_SYSCOMMAND = 0x112; //系统消息 private const int SC_SCREENSAVE = 0xf140; // 启动屏幕保护消息 private const int SC_MONITORPOWER = 0xF170; //关闭显示器的系统命令 private const int POWER_OFF = 2; //2 为关闭, 1为省电状态,-1为开机 private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff); //广播消息,所有顶级窗体都会接收 [System.Runtime.InteropServices.DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); static void Main() { SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, POWER_OFF); // 关闭显示器 // SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_SCREENSAVE, 0); // 启动屏保 } }
refurl:http://zhidao.baidu.com/question/371045320.html
2、DOS黑屏命令:
POWERCFG -Change -monitor-timeout-ac 5
这句话和调整显示器变黑是一样的,最低只能调到1分钟。
refurl:http://www.cnblogs.com/zzyn/archive/2009/08/06/1540241.html
2、软件锁屏代码:
public void testLockScreen() {
try {
Runtime.getRuntime().exec("RunDll32.exe user32.dll,LockWorkStation");
} catch (Exception e) {
e.printStackTrace();
}
}
refurl:http://blog.csdn.net/huoyin/article/details/2997060