Sleep/Hibernate the system using C#20th Jan 2010
I was in the process of building an application that requires putting the system to sleep or hibernate depending on the option that the user selected. I found a very simple way to add this functionality to my existing application.
Let's get straight in to it, simply using the following code will allow you to Sleep or Hibernate your system.
If you would like to use Interop Services then the following implementation will be helpful
// Hibernate Application.SetSuspendState(PowerState.Hibernate, true, true); // Standby Application.SetSuspendState(PowerState.Suspend, true, true);
[DllImport("Powrprof.dll", CharSet=CharSet.Auto, ExactSpelling=true)] public static extern bool SetSuspendState(bool hiberate, bool forceCritical, bool disableWakeEvent); // Hibernate SetSuspendState(true, true, true); // Standby SetSuspendState(false, true, true);