Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any Win32 API to trigger the hibernate or suspend mode in Windows?

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?

like image 675
aJ. Avatar asked Jun 06 '09 12:06

aJ.


People also ask

What is the purpose of the Win32 API?

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.

Which API used in 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.

How do I disable hibernation in Windows 11?

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.


2 Answers

Check out SetSuspendState.

Note that you need SE_SHUTDOWN_NAME privilege, as mentioned on the referenced msdn page.

like image 145
Ben Schwehn Avatar answered Oct 09 '22 04:10

Ben Schwehn


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.

like image 38
Anders Avatar answered Oct 09 '22 05:10

Anders