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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

win7休眠、待机api

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

win7休眠、待機(jī)api

通過c++讓windows進(jìn)入休眠或者待機(jī)狀態(tài)。
xp、win7下用SetSystemPowerState函數(shù),vista及之后的版本使用 SetSuspendState函數(shù)。

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.
參數(shù)值為真則待機(jī),參數(shù)值為假則休眠。
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.

休眠與待機(jī)的區(qū)別
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.

待機(jī)是關(guān)閉電源(暫且將Suspends翻譯為待機(jī))。那么言下之意休眠就不是關(guān)閉電源了。那休眠是什么狀態(tài)呢?硬盤關(guān)閉,風(fēng)扇關(guān)閉,但是內(nèi)存還上著電呢,用戶點擊鼠標(biāo)或者鍵盤之后電腦就會自動恢復(fù)了。

而在待機(jī)狀態(tài)下,點擊鼠標(biāo)鍵盤是不管用的,必須重新點開機(jī)按鈕才行。開機(jī)后進(jìn)入之前保留的狀態(tài)。

臆想是上面那樣的,而MicroSoft做了更細(xì)致的劃分。

詳細(xì)介紹如下

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.

調(diào)用此api需要特權(quán),通過AdjustTokenPrivileges來獲取特權(quán)。

示例

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);

總結(jié)

以上是生活随笔為你收集整理的win7休眠、待机api的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。