Is there any Win32 API to put the machine into hibernate or suspend mode?
I read MSDN and found that WM_POWERBROADCAST
message gets broadcasted when power-management events occur. I thought of simulating the same with PostMessage(WM_POWERBROADCAST)
. Is this the correct way of doing or any Win32 API exists to achieve this?
The Win32 API (also called the Windows API) is the native platform for Windows apps. This API is best for desktop apps that require direct access to system features and hardware. The Windows API can be used in all desktop apps, and the same functions are generally supported on 32-bit and 64-bit Windows.
The Windows UI API creates and uses windows to display output, prompt for user input, and carry out the other tasks that support interaction with the user. Most applications create at least one window.
Press the Win key and click on the power button icon in the Start menu. You will see that hibernate option is available in the start menu now. If you want to disable the hibernate feature, retrace the above steps and uncheck the Hibernate checkbox. Then click on the Save changes button to disable the feature.
Check out
SetSuspendState
.
Note that you need SE_SHUTDOWN_NAME privilege, as mentioned on the referenced msdn page.
As posted by Ben Schwehn, SetSuspendState is the way to go. On win95, you should call SetSystemPowerState. You can also call IsPwrSuspendAllowed and IsPwrHibernateAllowed or GetPwrCapabilities to tell if the machine supports suspend/hibernate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With