Search code examples
c#wpfwindows-8.1shutdownpower-state

Shutting down to PowerState S4


I need to shut down from my WPF application, and ensure the machine enters the same power state as using the traditional windows shutdown dialog.

I can shutdown to an unknown power state by using the following:

Process.Start("shutdown", "/s /t 0");

The problem is that using this shutdown process, when booting back up by pressing the power button, the psu draws less than 100 milliamps (usually between 80 and 85), as opposed to the ~300 milliamps drawn after using the dialog to shutdown.

Using the Shutdown dialog to shutdown, by default in windows 8, according the the System Power States enumeration is S4.

I would like to shutdown to that same S4 state, without forcing the user to make additional actions, clicking "ok" to shutdown on the dialog, etc.

Note:

I can call the dialog, by running the following VBScript, but would prefer not to take this route:

Call

Process.Start(@"C:\PathToScript\Shutdown.vbs");

VB Script

dim objShell
set objShell = CreateObject("shell.application")
objshell.ShutdownWindows
set objShell = nothing

Solution

  • I found that this is due to a new Windows 8 feature called "Hybrid Shutdown". It's closer to hybernate than an actual shutdown. Thankfully the shutdown command accepts /hybrid to enter this mode, mimicking the Windows 8 dialog shutdown.

    Process.Start("shutdown", "/s /f /hybrid /t 0");
    

    Note: Restarting will recycle the kernel. "Shutting Down" is not really shutting down, and will not. More about their fast boot logic here.