对电脑的控制需要调用系统api
调用系统api的方法:
1:using System.Runtime.InteropServices;
2:引入dll,格式为[DllImport("User32")]
3:api声明,格式为internal static extern bool ExitWindowsEx(int flg, int rea);
关机 注销 重启 等操作的方法实现网上很多,一个链接
http://blog.youkuaiyun.com/ylqmf/archive/2010/01/04/5128330.aspx
但待机的方法尚未多见
使用电源管理api
BOOL WINAPI SetSystemPowerState(
__in BOOL fSuspend,
__in BOOL fForce
);
参数
fSuspend [in]
-
参数为ture系统挂起(suspend);参数为false系统存盘待机(hibernate)
-
suspend 是系统当前参数保存到内存,cpu电源尚开
-
hibernate是保存到硬盘,cpu电源关闭
-
所以suspend的待机和唤醒都要比hibernate快
-
fForce [in]
-
无效
详情见http://msdn.microsoft.com/en-us/library/aa373206(VS.85).aspx
本文介绍如何通过调用Windows系统的API实现电脑的挂起(suspend)与存盘待机(hibernate)。挂起将系统状态保存至内存并保持CPU开启,而存盘待机则将状态保存至硬盘并关闭CPU电源。文章提供了SetSystemPowerState函数的具体使用方法。
819





