Restart computer from WinForms app?

bevacqua picture bevacqua · Nov 26, 2010 · Viewed 13k times · Source

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.

Answer

Hassan picture Hassan · Nov 26, 2010

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