繁体   English   中英

如何在Visual Studio中使用C#代码从Windows 8.1商店应用程序重新启动Windows设备?

[英]How to restart a windows device from my windows 8.1 store app using c# code in visual studios?

嗨,大家好,我正在使用Visual Studio,C#和XAML创建Windows 8.1应用程序。 我想知道是否有一些我可以使用的C#代码可以在应用运行时自动重新启动Windows用户设备? 因此,为了清楚起见,用户可以在我的应用程序中按一个按钮,例如,他们的设备可能提示他们然后重新启动?

我正在使用的一些代码:

    [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool InitiateShutdown(string lpMachineName,
        string lpMessage,
        UInt32 dwGracePeriod,
        UInt32 dwShutdownFlags,
        UInt32 dwReason);

    public static void ShutdownWorkstation()
    {
        UInt32 flags = 0x8;
        UInt32 reason = 0;
        UInt32 gracePeriod = 5;
        InitiateShutdown(System.Environment.MachineName, "", gracePeriod, flags, reason);
        //Console.WriteLine("Dummy Shutdown");
    }

    public static void RestartWorkstation()
    {
        UInt32 flags = 0x4;
        UInt32 reason = 0;
        UInt32 gracePeriod = 5;
        InitiateShutdown(System.Environment.MachineName, "", gracePeriod, flags, reason);
        //Console.WriteLine("Dummy Restart");
    }

编辑(关于上面有关WinRt的评论):如果使用WinRT,则可能需要关注以下帖子: 从Metro应用程序关闭Windows 8

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM