I want to invoke a shutdown if label1.text == label2.text
but an error appears when Windows.System.ShutdownManager.BeginShutdown(Windows.System.ShutdownKind.Shutdown, TimeSpan.FromSeconds(1));
is called.
The error:
System.UnauthorizedAccessException : 'Accès refusé. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))'
// Shutdowns the device within 1 second:
ShutdownManager.BeginShutdown(ShutdownKind.Shutdown, TimeSpan.FromSeconds(1));
In order for this code to work properly, you need to give an extra capability to your app, open the Package.appxmanifest
file with Visual Studio XML Editor and add :
<Package
...
<Capabilities>
...
<iot:Capability Name="systemManagement" />
</Capabilities>
</Package>
If you don't set this capability, you will get an UnauthorizedAccessException
error when calling ShutdownManager
methods
From Microsoft docs
This API requires the use of the IoT systemManagement capability. Users can add the following to their Package.appmanifest:
<iot:Capability Name="systemManagement"/>
ShutdownManager API requires the use of the IoT systemManagement capability, and the inclusion of iot in the IgnorableNamespaces list. Users can add the following to their Package.appmanifest:, and add iot to their existing list of IgnorableNamespaces.
<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">
User contributions licensed under CC BY-SA 3.0