{"id":108312,"date":"2023-06-08T07:00:00","date_gmt":"2023-06-08T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=108312"},"modified":"2023-06-09T10:00:26","modified_gmt":"2023-06-09T17:00:26","slug":"20230608-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20230608-00\/?p=108312","title":{"rendered":"How can I register a program to auto-relaunch if it crashes or is terminated?, redux"},"content":{"rendered":"<p>Some time ago, I wrote on the topic of <a title=\"How can I register a program to auto-relaunch if it crashes or is terminated?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20170605-00\/?p=96275\"> auto-restarting a program when it crashes or terminates<\/a>. 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.<\/p>\n<p>The <code>Register\u00adApplication\u00adRestart<\/code> 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.<\/p>\n<p>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.<\/p>\n<p><b>Bonus chatter<\/b>: 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can get a little bit of the way there.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-108312","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You can get a little bit of the way there.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/108312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=108312"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/108312\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=108312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=108312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=108312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}