views:

489

answers:

2

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?

+6  A: 

Check out SetSuspendState.

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

Ben Schwehn
Beat me to it! I fixed the link in your post. Hope you don't mind.
John Feminella
+1  A: 

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.

Anders