Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart computer from WinForms app?

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.

like image 393
bevacqua Avatar asked Nov 26 '10 15:11

bevacqua


1 Answers

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

like image 63
Hassan Avatar answered Sep 28 '22 09:09

Hassan