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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4286354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:40:52  来源:igfitidea点击:

Restart computer from WinForms app?

c#windowsrestart

提问by bevacqua

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?

我的问题是这会显示“Windows 将在 5...4...3... 中灾难性地重新启动”这样的对话框,非常让人联想到 Blaster,如何在不弹出任何对话框的情况下静默重新启动 Windows?

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.

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

采纳答案by Hassan

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

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