Answered by:
Shutdown Windows 8 with C#

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
Answers
-
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.
--Rob
- Marked as answer by Rob Caplan [MSFT]Microsoft employee, Moderator Tuesday, April 3, 2012 7:19 PM
Tuesday, April 3, 2012 7:19 PMModerator -
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".
--Rob
- Marked as answer by Rob Caplan [MSFT]Microsoft employee, Moderator Saturday, January 5, 2013 1:05 AM
Saturday, January 5, 2013 1:04 AMModerator
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.
--Rob
- Marked as answer by Rob Caplan [MSFT]Microsoft employee, Moderator Tuesday, April 3, 2012 7:19 PM
Tuesday, April 3, 2012 7:19 PMModerator -
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".
--Rob
- Marked as answer by Rob Caplan [MSFT]Microsoft employee, Moderator Saturday, January 5, 2013 1:05 AM
Saturday, January 5, 2013 1:04 AMModerator -
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);
- Proposed as answer by Himanshu12221 Saturday, January 5, 2013 1:11 AM
- Unproposed as answer by Rob Caplan [MSFT]Microsoft employee, Moderator Saturday, January 5, 2013 1:12 AM
Saturday, January 5, 2013 1:11 AM -
Process.Start is not available to Windows Store apps.
Saturday, January 5, 2013 1:13 AMModerator -
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