views:

441

answers:

2

What API or tools can I use to query the capabilities of the system and choose the most appropriate on for putting the PC to Sleep, Hibernate or shutdown mode?

Thanks for any pointers.

+7  A: 

Look at SystemInformation.PowerStatus, then you can call Application.SetSuspendState to put the PC to Sleep or Hibernate like:

Application.SetSuspendState(PowerState.Hibernate, true, true);
Leon Tayson
See http://msdn.microsoft.com/en-us/library/system.windows.forms.application.setsuspendstate.aspx for the full details
John
Full method signature: Application.SetSuspendState([PowerState.Hibernate | PowerState.Suspend], bool force, bool disableWakeEvent)
Simon_Weaver
depending upon the application needs i would recommend carefully considering the true, true parameters. sending true for the 'force' parameter may cause some applications or driver problems resuming because they won't be sent the suspend request. if you experience problems waking up try switching true, true to false, true or false, false
Simon_Weaver
Note: this is in the System.Windows.Forms namespace, so if you're using a WPF Application you'll need to add a reference to System.Windows.Forms DLL and call it using System.Windows.Forms.Application.SetSuspendState(PowerState.Suspend, true, true)
Simon_Weaver
+2  A: 

I found this from googling - just tried it and it worked fine:

http://gammadyne.com/cmdline.htm#sleep

Software Monkey