UWP - 使用 ShutdownManager 关闭设备

UWP - Shutting down device using ShutdownManager

系统特性

Windows 10 专业版 1903

描述

我在 Windows 10 Pro 平板电脑上有一个 UWP 应用程序 运行 处于信息亭模式。我希望应用程序在应用程序流程结束时关闭我的设备。我正在尝试使用

来达到它

ShutdownManager.BeginShutdown(ShutdownKind.Shutdown, TimeSpan.FromSeconds(5));

如文档所述,我在我的应用程序清单中添加了 iot 功能,在 IgnorableNamespace 字段中添加了 iot 字段。 问题是这段代码只关闭了我的应用程序而没有关闭设备。

如 ShutdownManager 文档所述:

ShutdownManager.BeginShutdown Shuts down a device that runs in fixed-purpose mode, and optionally restarts the device after the specified number of seconds.

固定用途模式可能是问题所在吗? 还有其他方法可以达到我的目标吗?

提前致谢

The problem is that this code only close my application and not shut down the device.

您可以在上面的行中添加调试点,它会抛出异常(访问被拒绝。(Exception from HRESULT: 0x80070005 E_ACCESSDENIED)并使您的应用程序崩溃,它看起来关闭了应用程序。实际上应用程序崩溃了。

BeginShutdown方法只适用于物联网设备,如树莓派等物联网专用OS。它不适用于 Windows 10 Pro 平板电脑,如果您确实要关闭设备,我们建议您使用桌面桥为 uwp 应用程序制作桌面扩展并使用 Win32 关闭计算机 api Process.Start("shutdown", "/s /f /t 0");.