Search code examples
c#windows-8sleepshutdown

Get all power options available


I have Windows 8 and the Power options are too hard to get to so i want to make a little app to replicate Power tab.

What i can't do is find a way to make windows Sleep. In windows 8 when the PC is Sleeping it is completely stopped and if you press a key it goes to Lock Screen instantaneously without the boot screen.

How can I accomplish that?

UPDATE: Or if it is possible to get a list of all power options available. ie: if hibernation is allowed...

I am using rundll32.exe powrprof.dll,SetSuspendState 0,1,0 to sleep PC now but it wakes very slow.


Solution

  • This should help you.

    I think you can lock the pc and then put it to sleep.

    To lock the screen:

    [DllImport("user32.dll", SetLastError = true)]
    static extern bool LockWorkStation();
    

    For entering sleep mode:

    Application.SetSuspendState(PowerState.Suspend, false, false);