Package標籤內加入
xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10"
IgnorableNamespaces新增
iot
Capabilities內加入
<iot:Capability Name="systemManagement" />
程式碼:
//立即關機
ShutdownManager.BeginShutdown(ShutdownKind.Shutdown, new TimeSpan(0));
//立即重新開機
ShutdownManager.BeginShutdown(ShutdownKind.Restart, new TimeSpan(0));
參考資料:
https://docs.microsoft.com/en-us/uwp/api/windows.system.shutdownmanager
https://msdn.microsoft.com/en-us/library/windows/apps/mt694883.aspx