win7休眠、待机api

通过c++让windows进入休眠或者待机状态。
xp、win7下用SetSystemPowerState函数,vista及之后的版本使用 SetSuspendState函数。

xp、win7:

SetSystemPowerState

BOOL WINAPI SetSystemPowerState(_In_ BOOL fSuspend,_In_ BOOL fForce
);

Parameters
fSuspend [in]
If this parameter is TRUE, the system is suspended. If the parameter is FALSE, the system hibernates.
参数值为真则待机,参数值为假则休眠。
fForce [in]
This parameter has no effect.

Return value
If power has been suspended and subsequently restored, the return value is nonzero.
If the system was not suspended, the return value is zero. To get extended error information, call GetLastError.

休眠与待机的区别
Suspends the system by shutting power down. Depending on the ForceFlag parameter, the function either suspends operation immediately or requests permission from all applications and device drivers before doing so.

待机是关闭电源(暂且将Suspends翻译为待机)。那么言下之意休眠就不是关闭电源了。那休眠是什么状态呢?硬盘关闭,风扇关闭,但是内存还上着电呢,用户点击鼠标或者键盘之后电脑就会自动恢复了。

而在待机状态下,点击鼠标键盘是不管用的,必须重新点开机按钮才行。开机后进入之前保留的状态。

臆想是上面那样的,而MicroSoft做了更细致的划分。

详细介绍如下

Power state ACPI state Description
Working S0 The system is fully usable. Hardware components that are not in use can save power by entering a lower power state.
Sleep (Modern Standby) S0 low-power idle Some SoC systems support a low-power idle state known as Modern Standby. In this state, the system can very quickly switch from a low-power state to high-power state, so that it can respond quickly to hardware and network events. Systems that support Modern Standby do not use S1-S3.
Sleep S1 S2 S3 The system appears to be off. Power consumed in these states (S1-S3) is less than S0 and more than S4; S3 consumes less power than S2, and S2 consumes less power than S1. Systems typically support one of these three states, not all three. In these states (S1-S3), volatile memory is kept refreshed to maintain the system state. Some components remain powered so the computer can wake from input from the keyboard, LAN, or a USB device. Hybrid sleep, used on desktops, is where a system uses a hibernation file with S1-S3. The hibernation file saves the system state in case the system loses power while in sleep. Note SoC systems that support modern standby (the low-power idle state) do not use S1-S3.
Hibernate S4 The system appears to be off. Power consumption is reduced to the lowest level. The system saves the contents of volatile memory to a hibernation file to preserve system state. Some components remain powered so the computer can wake from input from the keyboard, LAN, or a USB device. The working context can be restored if it is stored on nonvolatile media.Fast startup is where the user is logged off before the hibernation file is created. This allows for a smaller hibernation file, more appropriate for systems with less storage capabilities.
Soft Off S5 The system appears to be off. This state is comprised of a full shutdown and boot cycle.
Mechanical Off G3 The system is completely off and consumes no power. The system returns to the working state only after a full reboot.

Remarks
The calling process must have the SE_SHUTDOWN_NAME privilege. To enable the SE_SHUTDOWN_NAME privilege, use the AdjustTokenPrivileges function. For more information, see Changing Privileges in a Token.
If any application or driver denies permission to suspend operation, the function broadcasts a PBT_APMQUERYSUSPENDFAILED event to each application and driver. If power is suspended, this function returns only after system operation is resumed and related WM_POWERBROADCAST messages have been broadcast to all applications and drivers.
This function is similar to the SetSuspendState function.
To compile an application that uses this function, define the _WIN32_WINNT macro as 0x0400 or later. For more information, see Using the Windows Headers.

调用此api需要特权,通过AdjustTokenPrivileges来获取特权。

示例

 HANDLE hToken;TOKEN_PRIVILEGES tp;LUID luid;if(::OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken)){::LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid);tp.PrivilegeCount=1;tp.Privileges[0].Luid =luid;tp.Privileges[0].Attributes =SE_PRIVILEGE_ENABLED;::AdjustTokenPrivileges(hToken,false,&tp,sizeof(TOKEN_PRIVILEGES),NULL,NULL);}::SetSystemPowerState(false,true);

win7休眠、待机api相关推荐

  1. 计算机休眠唤醒后 网络受限,Win7系统待机/休眠被唤醒后笔记本WIFI无线网络无法连接解决方法...

    有的时候,我们会暂时离开电脑,希望回来的时候又可以快速使用电脑,所以我们经常会使用待机.休眠功能,当我们将系统待机时,不仅可以快速的恢复到之前电脑的工作状态,还可以省电.但是我们使用笔记本的时候,发现 ...

  2. 计算机win7自动休眠设置在哪里设置密码,win7系统设置待机密码的简单方法(图文)...

    本教程小编分享雨林木风win7系统设置待机密码的简单方法?Win7系统电脑一般都会有些私密文件,一些用户不想被别人看到,又是需有事需离开电脑一会,这是待机密码就派上用场了,而待机密码设置前提是设置开机 ...

  3. 怎么调解计算机休眠不断网,怎么设置Win7不待机 Win7进入待机状态会断网的解决方法...

    有时候我们需要挂一些游戏或者应用的时候,希望人在电脑面前的时候,电脑不进入待机状态,因为一旦进入待机状态后,会断网,应用将停止运行,因此需要设置电脑不待机来解决.那么电脑不待机怎么设置呢?以下我们以W ...

  4. win7休眠的开启与关闭方法命令行操作和图文结合的鼠标操作

    win7休眠的开启与关闭方法 从开始菜单中找到"附件→命令提示符",手工输入如下命令:powercfg -a,从这里可以清楚的看到,计算机是支持休眠的,显示"尚未启用休眠 ...

  5. Win7休眠后唤醒出现黑屏的解决办法

    进入睡眠状态可很好地节约电源和延长硬件的使用寿命,很多用户的电脑进入睡眠状态后,唤醒无法正常进入屏幕,而是变成黑屏的故障,怎么回事?其实出现这种情况并非什么系统故障问题,下面小编给大家分享Win7休眠 ...

  6. 服务器2008系统如何设置休眠时间,Win7休眠和睡眠怎么开启(Win2008)

    如果把 Win7休眠和睡眠关闭了,需要的时候可以用命令重新开启,毕竟这两个功能不但可以节约电,还可以迅速恢复工作状态,节约开机开软件的时间.Win2008 R2 跟 Win7 同一内核,开启休眠和睡眠 ...

  7. 计算机休眠后无法唤醒硬盘,大师给你说win10电脑休眠待机后无法唤醒固态硬盘的完全解决办法...

    今日有网友来向小编反馈说他在使用系统的时候遇到了win10电脑休眠待机后无法唤醒固态硬盘的问题,这个对于那些比较熟悉win10系统的网友处理起来很简单,但是不太熟悉电脑的网友面对win10电脑休眠待机 ...

  8. 如何设置Win7不待机 Win7进入待机状态会断网的解决方法

    进入待机状态后,会断网,应用将停止运行,因此需要设置电脑不待机来解决,这种情况需要挂一些游戏或者下载应用的时非常实用,下面就与大家分享下电脑不待机的设置方法,感兴趣的朋友可以参考下 有时候我们需要挂一 ...

  9. 笔记本 win7 不能待机 不能休眠

    也不知道搞了什么,以前的待机是正常,后来不能用了,从高手那里找到的,原文连接: http://wenzhen.me/2011/10/%E8%A7%A3%E5%86%B3windows7%E6%97%A ...

  10. win7 休眠锁定计算机,win7怎么设置待机时间

    在我们使用电脑的时候,电脑开机着但是要是一段时间没有人去碰的话电脑就会自动锁定进入待机状态,然后待机的时候网络就会掉线了,然而要是有下载东西的话就会被暂停下载了,很多用户认为这样比较麻烦却不知道要如何 ...

最新文章

  1. lvm快照的创建恢复
  2. 减少运维工作量,如何通过 ROS 轻松实现资源编排新方式
  3. boost::locale::generator用法的测试程序
  4. Taro+react开发(13)--多加/不然不能跳转
  5. “约见”面试官系列之常见面试题之第五十九篇之js中push(),pop(),unshift(),shift()的用法小结 (建议收藏)
  6. 今日头条人群洞察报告
  7. 【WordPress 建站教程】在 正文顶端或末尾插入固定的内容
  8. 面试精讲之面试考点及大厂真题 - 分布式专栏 14 全面了解Kafka的使用与特性
  9. vb html table,VB6.0 如何是用 datatable
  10. HDU 3328 Flipper 栈 模拟
  11. 您的计算机已实施了USB存储设备管理策略,设置usb设备管理 【解决步骤】 的教程_...
  12. 一文读懂机器学习、数据科学、人工智能、深度学习和统计学之间的区别
  13. ORACLE VARCHAR2
  14. java中怎么把系统格式化_如何在java中格式化1200到1.2k
  15. 【日期工具类】DateUtils
  16. 数字图像处理——基于matlab的车牌号识别
  17. Scientific Reports|比较转录组分析揭示了杀菌剂氰烯菌酯对尖孢镰刀菌的抗性调控机制和杀菌活性
  18. 公司规章制度制度(受不了)
  19. springmvc ResponseEntity 下载文件损坏问题解决方法
  20. Free Launch Bar

热门文章

  1. HR告诉你,怎么回答“为什么从上家公司离职?”
  2. 路由器映射,端口映射?
  3. 用户行为监控(Piwik)
  4. 从zookeeper官方文档系统学习zookeeper
  5. 学做衣服论坛 -服装DIY教程,缤纷服装网,裁剪教程,家用缝纫机,买布料
  6. 安徽省对口计算机试题答案,安徽省对口高考试卷
  7. SAP UD取消处理合订本
  8. win服务器系统下的软路由,如何用Windows 2000 Server充当软路由
  9. H3C路由器静态NAT_不同网段的两个路由器如何互通?
  10. 国内域名转入到AWS-Route53的操作实践经验分享