Shutdown Windows 8 with C# RRS feed

  • Question

  • Hi,

    I just start on Windows 8 and I think it should not be very difficult, but I can't find how to shutdown the computer with C#.

    Thank you.

    • Edited by sablier94 Tuesday, April 3, 2012 7:15 PM
    Tuesday, April 3, 2012 7:09 PM


All replies

  • Metro style apps cannot affect the computer as a whole. There is no way provided to shutdown windows from a Metro style app.

    If you want to do this from a Desktop app then you'll probably need to p-invoke Win32 functions. See: How to Shut Down the System.


    Tuesday, April 3, 2012 7:19 PM
  • Okay, so we can't do this even through a Win32 function or by executing the dos command from a Metro style application ! =(

    Thank you for the help
    • Edited by sablier94 Tuesday, April 3, 2012 7:35 PM
    Tuesday, April 3, 2012 7:30 PM
  • Hey Rob, can you point me in the direction of some Microsoft documentation, on say TechNet or a MSFT Team blog or something, that states this?

    I just need to confirm before abandoning an idea I have.

    Thanks in advance.

    Saturday, January 5, 2013 12:46 AM
  • Hi Steven,

    The Building Windows 8 blog discusses the trust model for Windows Store apps at Delivering reliable and trustworthy Metro style apps .

    Win32 and COM API discusses the native API which are available to Windows Store apps. If you look at the functions used to shutdown the system (ExitWindowsEx, etc.) you will see that they are marked "desktop apps only".


    Saturday, January 5, 2013 1:04 AM
  • Hi,

    Can you try with code mentioned in the following link: https://gist.github.com/3844522

    ProcessStartInfo psi = new ProcessStartInfo();
    psi.FileName = "shutdown.exe";
    psi.Arguments = "-r -f -t 0";
    psi.CreateNoWindow = true;
    Process p = Process.Start(psi);

    Saturday, January 5, 2013 1:11 AM
  • Process.Start is not available to Windows Store apps.

    Saturday, January 5, 2013 1:13 AM
  • Thank you, Rob.  I'm disappointed but I appreciate the information.

    While I am here, you know any good articles discussing file level security and the differences between Win8 and Win7?

    It looks like a lot of changes made and I'd like to read up on it.

    Saturday, January 5, 2013 1:48 AM