开发者

Restart computer from WinForms app?

开发者 https://www.devze.com 2023-01-26 21:37 出处:网络
Right now I\'m restarting my app with the following code private static void Restart() { ProcessStartInfo proc = new ProcessStartInfo();

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

private static void Restart()
{
    ProcessStartInfo proc = new ProcessStartInfo();
    proc.WindowStyle = Pr开发者_开发问答ocessWindowStyle.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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号