views:

425

answers:

2

Hi,

I want to put my system to either sleep or hibernate, two different options.

How would I do this with API's, I don't really want to use Process, and that doesn't allow me to choose what method I want for this action.

Thanks.

+4  A: 

You can find all the information you need in this link for locking the PC, stand by mode, hibernating and logging off.

Alex
Thanks, I needed the lock PC code as well.
Sandeep Bansal
+1  A: 
// Hibernate
Application.SetSuspendState(PowerState.Hibernate, true, true);
// Standby
Application.SetSuspendState(PowerState.Suspend true, true);

Or, if you like system calls:

[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);
fre0n
Thanks, very informative and helpful.
Sandeep Bansal