<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10"
IgnorableNamespaces="uap mp iot">
...
<Capabilities>
<iot:Capability Name="systemManagement"/>
</Capabilities>
...
However, I still get UnauthorizedAccessException
when executing the code, no matter which code I run (Shutdown or Restart). I already tried uninstalling the app and load it again from VS.
System.UnauthorizedAccessException: 'Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))'
Did I miss something? How do I resolve this?
UPDATE: so I tried adding this line to test if I actually have access to this capacity:
var temp = ShutdownManager.IsPowerStateSupported(PowerState.ConnectedStandby);
UPDATE 2: Apparently this API is for IoT devices only? Can I use this API on Windows Desktop device or is there any similar API? Google always lead me there and there doesn't seem to be any alternative.
CodePudding user response:
This API is designed for IoT devices and the function is not supported in UWP apps. UWP apps are running in a sandbox that is isolated so UWP apps have limited access to system resources and are not allowed to access these system functions like shutting down the device.