国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > OS > Windows7 > 正文

win7休眠、待機api

2024-06-28 16:00:54
字體:
來源:轉載
供稿:網友

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);
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新绛县| 拉孜县| 札达县| 台北县| 颍上县| 保定市| 青龙| 务川| 湄潭县| 石渠县| 高尔夫| 吴江市| 芮城县| 井研县| 新丰县| 大丰市| 阳泉市| 化德县| 渭源县| 平昌县| 静海县| 宜昌市| 阿合奇县| 奉贤区| 丰顺县| 丰原市| 包头市| 黑河市| 合山市| 慈利县| 巫溪县| 岳普湖县| 永嘉县| 阿尔山市| 福贡县| 霍山县| 霍林郭勒市| 辰溪县| 固镇县| 新兴县| 邹城市|