1

I'm doing a metro app for Windows 8. And as part of its functionality, I need to initiate shutdown of Winodws 8 from the Metro App. Here are the questions:

1) Firstly, I researched a lot on this topic and I found out that System.Diagnostics.Process is not available for Metro App. So, is there a another way around?

2) Even if I can't directly shutdown, is there a way to trigger it from the Metro App?

I would prefer a solution in C#.

Thanks.

felarof99
  • 185
  • 1
  • 1
  • 9
  • I also did some research about it and from what I had read so far, I think there's no such direct solution for the problem. Please find below couple of links which will guide you [ Shutdown Windows 8 with C#](http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/571a0bc6-3e84-4f7c-af51-20b809246407) [Metro App can no longer be programmatically killed?](http://) – Amal Dev Sep 30 '12 at 05:26
  • As a matter of fact, you can programmatically have a Windows Store application kill itself. It's pretty easy actually: just throw an uncaught exception. But you should not do it. – Falanwe Sep 30 '12 at 10:02
  • related: http://stackoverflow.com/a/27726215/294884 – Fattie Apr 11 '15 at 03:42

2 Answers2

6

Doing this just isn't possible in a Windows Store (aka Metro) app. Such apps are strictly limited in what they can do, nothing that affects the way the operating system works or affects other processes running on the same machine is possible.

These restrictions are enforced by omission if you program in a managed language. The .NET framework class you hope to use is just missing. If you program in a native language like C++ then you can try to work around it by using the winapi. But that doesn't work either, a Windows Store app runs in a sandbox that simply fails the api call. Very similar to the Protected Mode feature of Internet Explorer, the security model is named "App Container". And enforced by the store screening procedure, even if you did find a hole in the sandbox then you can't get it past the validator and can't get it published in the app store.

Key point here is that it just doesn't make sense to write a store app to reboot the machine. Because there is nothing such an app could do that requires a reboot.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
-2

To shut down or reboot Windows 8, just shell to the following:

Shutdown:

%windir%\System32\shutdown.exe /s /t 0

Reboot:

%windir%\System32\shutdown.exe /r /t 0
Sebass van Boxel
  • 2,514
  • 1
  • 22
  • 37