How can I register a program to auto-relaunch if it crashes or is terminated?, redux

Raymond Chen

Some time ago, I wrote on the topic of auto-restarting a program when it crashes or terminates. If your program is a service, you can set the service restart policy, which will restart the service if it crashes. I mentioned that there is no similar feature for regular applications. Turns out I was wrong.

The Register­Application­Restart function lets you specify a command line to use if the current process crashes or hangs, or if the program had been running at the time the system restarted to install an update. You can also specify flags that modify the default restart conditions.

Note that if the program crashes or hangs, the program does not restart automatically. The system informs the user of the crash or hang, and then asks if they want to restart the program. Only if the user agrees does the system execute the restart command. Note also that the restart command is not executed if the user manually terminates the program, such as by using Task Manager. The idea of the restart command is to make it easier for the user to recover their work, not to give programs an easy means of persistent execution.

Bonus chatter: To avoid infinite restart loops, both service auto-restart and process auto-restart have minimum uptime requirements before they will restart the crashed process. You can read the documentation for details.

8 comments

Discussion is closed. Login to edit/delete existing comments.


Newest
Newest
Popular
Oldest
  • sugrob 9000 0

    So there’s the ¹ that hints at a footnote, but neither here nor the linked article has one. I really wanted the extra details!

  • Danielix Klimax 0

    OT: Could you please kick whoever is in charge of devblogs to fix search? it’s nearly impossible to find anything on your blog. (Either 0 or too few results) I tried feedback, but no improvement…

    Thanks.

  • Georg Rottensteiner 0

    Not exactly the same, but is this Auto Restarting also affecting the restart of a program after a update reboot?
    You know, when you do a restart, and Windows tries to restart all the programs that were running when you clicked on it.

    This restarting also infers that programs should be able to do a quick save and reload on restart of its current state (opened documents, etc.)

    Some programs (e.g. Contoso Alphanumeric Slab) unfortunately are not able to restore all documents. It usually works with the first document, but all others fail with a weird message.

    • Scarlet Manuka · Edited 0

      From the article: “… or if the program had been running at the time the system restarted to install an update”

      The point of this is to give applications a way to be prepared for a suden reboot and survive it with work intact. It’s up to the applications that make use of it to make sure they are actually fully prepared, and some certainly don’t do a great job.

      But even the ones that do a mediocre job give the user more to work with in terms of restoring their previous state than the ones that don’t try at all. Unfortunately, in my job, the most important programs I use are the ones that make no effort to preserve state on crash or reboot.

  • Dan Bugglin · Edited 0

    Ahh I wondered how that worked! I guess I thought it was magic Microsoft-only functionality. You know, the kind of stuff that would cause EU courts to throw a fit if they found out about it.

    Alright, MSDN says the API can restart an application if it is “updated” (an application update, OS updates are mentioned separately). What exactly would trigger this? Clearly if I just use a third-party installer like NSIS Windows wouldn’t really see it as anything more than another application running, so you couldn’t use this API for that with just this single API call. Is this a Windows Installer-specific thing?

    • Kalle Niemitalo 0

      Third-party installers can use the Restart Manager API.

Feedback usabilla icon