11

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.

bevacqua
  • 47,502
  • 56
  • 171
  • 285
  • 4
    It has nothing to do with Blaster :)) this is how Microsoft implemented the shutdown -f so the user can stop the restart process. – Stefan P. Nov 26 '10 at 15:06
  • Are you targeting Windows XP, or just Vista/7? – Richard Ev Nov 26 '10 at 15:06
  • 2
    Why do you want it not to pop-up? Won't that cause risky usability situations, with computer's restarting out from under people? – Andrew M Nov 26 '10 at 15:07
  • 7
    Don't. It's already bad enough that Windows Update does this, much less random apps. ("Whatever, I don't care about users, I, the developer, know best what's good for the lusers!") Every time an app did that, I felt like doing indescribable acts to its author. With a rusty spoon. (And I wondered what else the app was doing without my approval.) – Piskvor left the building Nov 26 '10 at 15:07
  • Why on earth are you shutting down the OS to restart your application? – ChrisF Nov 26 '10 at 15:08
  • @abatishchev http://en.wikipedia.org/wiki/Blaster_%28computer_worm%29 – AakashM Nov 26 '10 at 15:09
  • 6
    Tell me which app this is so that I never ever ever download it and install it. – Roopesh Shenoy Nov 26 '10 at 15:09
  • 1
    @Richard: I'm attempting to get something that's targeting all 3. @Piskvor: I never said it didn't ask for approval before restarting. – bevacqua Nov 26 '10 at 15:11
  • 1
    @Stefan: You know that. I know that. We can't assume users know anything. – bevacqua Nov 26 '10 at 15:16
  • @Nico, re edit: If you let the user decide whether to restart or not, it's OK with me. Sorry if I came across as rude - I probably misinterpreted "restart windows silently". Alas, there are still installers that think it's OK to force-kill everything without asking. – Piskvor left the building Nov 26 '10 at 15:17
  • You should have mentioned you were writing an installer in the first place. – ChrisF Nov 26 '10 at 17:15
  • I didn't think I'd get this much "love" if I didn't mention it. – bevacqua Nov 26 '10 at 18:13

1 Answers1

9

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

Hassan
  • 2,603
  • 2
  • 19
  • 18