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

3

8

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?

Flamethrower answered 6/6, 2009 at 12:27 Comment(0)
S
12

Check out SetSuspendState.

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

Salpingotomy answered 6/6, 2009 at 12:30 Comment(1)
Beat me to it! I fixed the link in your post. Hope you don't mind.Crowson
C
2

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.

Crap answered 9/6, 2009 at 17:22 Comment(0)
S
0

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

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

Sakai answered 10/1, 2013 at 23:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.