shutdown windows 8 from metro app

一笑奈何 提交于 2019-12-24 10:03:02

问题


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.


回答1:


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.




回答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


来源:https://stackoverflow.com/questions/12658828/shutdown-windows-8-from-metro-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!