从 WinForms 应用程序重新启动计算机?

发布于 2024-10-04 13:08:15 字数 497 浏览 0 评论 0原文

现在我正在使用以下代码重新启动我的应用程序

private static void Restart()
{
    ProcessStartInfo proc = new ProcessStartInfo();
    proc.WindowStyle = ProcessWindowStyle.Hidden;
    proc.FileName = "cmd";
    proc.Arguments = "/C shutdown -f -r -t 5";
    Process.Start(proc);
}

我的问题是显示“Windows 将在 5...4...3... 中灾难性地重新启动”类型的对话框,非常让人想起 Blaster,我该如何静默重新启动窗口,不弹出任何对话框?

更新:伙计们,呃,这是一个安装程序,它不会“只是突然重新启动计算机”,它会完成安装,然后询问您是否要重新启动,如果需要重新启动,那么确实如此,但它不需要任何蹩脚的系统对话框告诉您在重新启动之前等待 X 时间。

Right now I'm restarting my app with the following code

private static void Restart()
{
    ProcessStartInfo proc = new ProcessStartInfo();
    proc.WindowStyle = ProcessWindowStyle.Hidden;
    proc.FileName = "cmd";
    proc.Arguments = "/C shutdown -f -r -t 5";
    Process.Start(proc);
}

My problem is this displays a "Windows will catastrophically restart in 5...4...3..." kind of dialog box, very reminiscent of Blaster, how can I restart windows silently, without any dialogs popping up?

Update: Guys, ugh, it's for an installer, it doesn't "just restart your computer out of nowhere", it finishes installing and then asks you if you want to restart, if you do, then it does, but it doesn't need any crappy system dialog telling you to wait X time before it restarts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔一刀 2024-10-11 13:08:15

只需从参数列表中删除“-t 5”部分 - 它会立即重新启动计算机

just remove the "-t 5" part from your argument list - and it will immediately restart the computer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文