日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

win7休眠、待机api

發布時間:2023/12/20 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 win7休眠、待机api 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 stateACPI stateDescription
WorkingS0The 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 idleSome 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.
SleepS1 S2 S3The 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.
HibernateS4The 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 OffS5The system appears to be off. This state is comprised of a full shutdown and boot cycle.
Mechanical OffG3The 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。