{"id":12895,"date":"2025-08-18T06:15:02","date_gmt":"2025-08-18T13:15:02","guid":{"rendered":"https:\/\/www.coretechnologies.com\/blog\/?p=12895"},"modified":"2025-08-18T06:15:02","modified_gmt":"2025-08-18T13:15:02","slug":"restart-batch-file-hangs","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/restart-batch-file-hangs\/","title":{"rendered":"Q&#038;A: How Do I Force AlwaysUp To Restart My Batch File When It Hangs?"},"content":{"rendered":"<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"\/blog\/images\/qa-template-batch-file-hangs.webp\" style=\"margin-bottom:20px;\" title=\"How Do I Force AlwaysUp To Restart My Batch File When It Hangs?\" alt=\"How Do I Force AlwaysUp To Restart My Batch File When It Hangs?\" border=\"0\" width=\"380\" height=\"160\" \/><\/div>\n<div class=\"blog-qa-question-box\">\n<img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"https:\/\/cdn.coretechnologies.com\/images\/quotes-transparent-21x21.webp\" width=\"21\" height=\"21\" \/>&nbsp;&nbsp;I have a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Batch_file\" target=\"_blank\">batch file<\/a> I want to run once every minute. It copies certain files from one place to another. I have the batch file set so that AlwaysUp restarts it when it &#8220;fails&#8221; (stops running) as it is designed to do after a few seconds. That part works fine. <\/p>\n<p>But every now and then, the batch file continues running in some form or fashion &mdash; getting hung, I suppose &mdash; and of course AlwaysUp is satisfied and doesn&#8217;t restart it. I know I can have AlwaysUp restart it every day at a certain time, but I need the copying process to run very regularly. How do I make that happen?<\/p>\n<p align=\"right\">&mdash; Rowan<\/p>\n<\/div>\n<p>Hi Rowan. That&#8217;s an interesting scenario. A couple of solutions jump to mind&#8230;<\/p>\n<hr class=\"blog-section\">\n<h2 class=\"blog-caption\">Solution #1: Stop\/restart your batch file hourly<\/h2>\n<p>You mentioned that AlwaysUp can restart your batch file daily, but did you know that it can do so hourly as well?<\/p>\n<p>Edit your application in AlwaysUp and you&#8217;ll find that capability on the <b>Monitor<\/b> tab:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-restart-batch-file-every-hour.png\" class=\"zoomPopup\" title=\"Have AlwaysUp restart your batch file every hour\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-restart-batch-file-every-hour.png\" title=\"Have AlwaysUp restart your batch file every hour (click to enlarge)\" alt=\"Have AlwaysUp restart your batch file every hour\" border=\"0\" \/><\/a><\/div>\n<p>That&#8217;s the easiest way to protect your batch file from a prolonged hang. With the hourly setting in place, your batch file will never get stuck for more than 60 minutes. Furthermore, you&#8217;ll be guaranteed a &#8220;fresh&#8221; run of your batch file at the top of every hour.<\/p>\n<p>But what if you can&#8217;t wait for up to an hour? In that case, you&#8217;ll have to resort to the second solution. It involves a bit more work to set up, but in return it gives you much greater control.<\/p>\n<hr class=\"blog-section\">\n<h2 class=\"blog-caption\">Solution #2: Install a simple sanity check to stop\/restart your batch file when it runs for too long<\/h2>\n<p>Are you familiar with the <a href=\"\/products\/AlwaysUp\/SanityChecks\/\">AlwaysUp sanity check feature<\/a>? Basically, it&#8217;s a way to add sophisticated failure detection to the mix &mdash; and have AlwaysUp restart your application whenever something unusual happens. We&#8217;ll use a sanity check to restart your batch file if it runs for longer than you like.<\/p>\n<p>To set that up:<\/p>\n<ol style=\"margin-bottom:24px\">\n<li>\n<p>Create a new sanity check batch file with a single line:<\/p>\n<blockquote><p>exit 1<\/p><\/blockquote>\n<p>Save it to your hard drive:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-sanity-check-batch-file.png\" class=\"zoomPopup\" title=\"Create a sanity check batch file\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-sanity-check-batch-file.png\" title=\"Create a sanity check batch file (click to enlarge)\" alt=\"Create a sanity check batch file\" border=\"0\" \/><\/a><\/div>\n<\/li>\n<li>\n<p>Start AlwaysUp.<\/p>\n<\/li>\n<li>\n<p>Edit your batch file entry in AlwaysUp (by highlighting it and selecting <b>Application &gt; Edit\/View<\/b> from the menu).<\/p>\n<\/li>\n<li>\n<p>Switch to the <b>Monitor<\/b> tab.<\/p>\n<\/li>\n<li>\n<p>Check the <b>Whenever it fails a periodic sanity check<\/b> box and click the <b>Set<\/b> button:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-activate-sanity-check.png\" class=\"zoomPopup\" title=\"Activate the sanity check feature\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-activate-sanity-check.png\" title=\"Activate the sanity check feature (click to enlarge)\" alt=\"Activate the sanity check feature\" border=\"0\" \/><\/a><\/div>\n<\/li>\n<li>\n<p>In the <b>Add Sanity Check<\/b> window that comes up, select <b>Check your application with a custom executable\/script<\/b> from the list:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-select-custom-sanity-check.png\" class=\"zoomPopup\" title=\"Check your application with a custom executable\/script\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-select-custom-sanity-check.png\" title=\"Check your application with a custom executable\/script (click to enlarge)\" alt=\"Check your application with a custom executable\/script\" border=\"0\" \/><\/a><\/div>\n<p>Click <b>Next<\/b> to proceed.<\/p>\n<\/li>\n<li>\n<p>On the following page, enter the full path to the sanity check batch file you created in step 1:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/custom-sanity-check-batch-file-path.png\" class=\"zoomPopup\" title=\"Specify the batch file you created\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/custom-sanity-check-batch-file-path.png\" title=\"Specify the batch file you created (click to enlarge)\" alt=\"Specify the batch file you created\" border=\"0\" \/><\/a><\/div>\n<p>Click <b>Next<\/b> to move on.<\/p>\n<\/li>\n<li>\n<p>How long are you willing to wait for your main batch file to do its work? That is, for how long should your batch file run before it&#8217;s declared as hung and needs to be terminated?<\/p>\n<p>Whatever that duration is, enter it here. We&#8217;ve put in 2 minutes but you can go as low as 1 minute if you like:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/custom-sanity-check-enter-frequency.png\" class=\"zoomPopup\" title=\"Enter your batch file timeout\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/custom-sanity-check-enter-frequency.png\" title=\"Enter your batch file timeout (click to enlarge)\" alt=\"Enter your batch file timeout\" border=\"0\" \/><\/a><\/div>\n<\/li>\n<li>\n<p>Finally, review the summary and save your new sanity check:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/review-sanity-check-summary.png\" class=\"zoomPopup\" title=\"Review your sanity check and add it\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/review-sanity-check-summary.png\" title=\"Review your sanity check and add it (click to enlarge)\" alt=\"Review your sanity check and add it\" border=\"0\" \/><\/a><\/div>\n<\/li>\n<\/ol>\n<p>And with that sanity check in place, here&#8217;s what will happen whenever AlwaysUp runs your batch file:<\/p>\n<ul style=\"margin-bottom:24px\">\n<li>\n<p>The batch file starts<\/p>\n<\/li>\n<li>\n<p>If the batch file does its work and exits within 2 minutes, AlwaysUp will simply queue up the next run as you&#8217;ve specified on the <b>Restart<\/b> tab. All will be good.<\/p>\n<\/li>\n<li>\n<p>If, however, the batch file hangs and remains running for longer than 2 minutes:<\/p>\n<ul>\n<li>\n<p>A second or two after to the 2-minute mark, AlwaysUp runs the sanity check batch file.<\/p>\n<\/li>\n<li>\n<p>The sanity check batch file immediately exits with 1, which <a href=\"\/products\/AlwaysUp\/SanityChecks\/#writing-your-own\">signals AlwaysUp to terminate the main batch file<\/a>.<\/p>\n<\/li>\n<li>\n<p>AlwaysUp kills the main batch file, thereby interrupting a potentially lengthy hang.<\/p>\n<\/li>\n<li>\n<p>AlwaysUp queues up the next run as you&#8217;ve specified on the <b>Restart<\/b> tab.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>The end result is that your batch file will never run for more than a few seconds longer that two minutes &mdash; or whatever threshold you set for your situation.<\/p>\n<hr class=\"blog-section\">\n<p style=\"margin-top: 30px\">\nThanks again for reaching out, Rowan. Please try one (or both) of these solutions and let us know how you get on!\n<\/p>\n<div style=\"margin-top:30px\" align=\"center\">\n<div class=\"cta-button-1\">\n<table role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" align=\"left\">\n<tbody>\n<tr>\n<td align=\"center\"><a href=\"\/blog\/tag\/alwaysup-tag\/\" title=\"Click to read more articles about AlwaysUp\"><span><nobr>More articles about AlwaysUp&#8230;<\/nobr><\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/service-protector\/version-11-released\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Service Protector 11: Resource Monitoring, Help for Slow Services, and More\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/new-release-150x150-2.webp\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Service Protector 11: Resource Monitoring, Help for Slow Services, and More<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/how-to-restart-at-specific-time\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: How do I Restart my Windows Service at a Specific Time every Week?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/restart-service-schedule-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: How do I Restart my Windows Service at a Specific Time every Week?<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/start-service-without-admin-rights\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: How can a Non-Admin User Start my AlwaysUp Service?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/update-service-security-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: How can a Non-Admin User Start my AlwaysUp Service?<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp;I have a batch file I want to run once every minute. It copies certain files from one place to another. I have the batch file set so that AlwaysUp restarts it when it &#8220;fails&#8221; (stops running) as it is &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/restart-batch-file-hangs\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":12899,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[26,44,384,127,304,138],"class_list":["post-12895","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-alwaysup","tag-alwaysup-tag","tag-batch-file","tag-custom-sanity-check","tag-qa","tag-regular-restart","tag-sanity-check"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/12895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=12895"}],"version-history":[{"count":11,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/12895\/revisions"}],"predecessor-version":[{"id":13072,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/12895\/revisions\/13072"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/12899"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=12895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=12895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=12895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}