Is there any Win32 API to start hibernation or suspend on Windows?

Is there any Win32 API to put the machine to sleep or standby?

I read the MSDN and found that the message WM_POWERBROADCASTis sent when power management events occur. I was thinking of imitating the same thing with PostMessage(WM_POWERBROADCAST). Is this the right way to do it, or is there any Win32 API to achieve this?

+5
source share
3 answers

Check out SetSuspendState.

Please note that you need the SE_SHUTDOWN_NAME privilege as indicated on the msdn link page.

+11
source

Ben Schwehn, SetSuspendState - . win95 SetSystemPowerState. IsPwrSuspendAllowed IsPwrHibernateAllowed GetPwrCapabilities, , suspend/hibernate.

+1

In a Windows Form application, use the SetSUspendState method (http://msdn.microsoft.com/fr-fr/library/system.windows.forms.application.setsuspendstate.aspx). The first parameter allows you to choose between SUspend and Hibernate.

For a non-Windows application, call the Win32 API directly: the SetSuspendState function is located in the powrprof.dll file.

0
source

All Articles