{"id":11486,"date":"2022-11-22T07:29:29","date_gmt":"2022-11-22T15:29:29","guid":{"rendered":"https:\/\/www.coretechnologies.com\/blog\/?p=11486"},"modified":"2022-11-22T07:29:29","modified_gmt":"2022-11-22T15:29:29","slug":"run-script-service-periodically","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/run-script-service-periodically\/","title":{"rendered":"Q&#038;A: How do I Run my Script as a Windows Service &mdash; but only during Working Hours?"},"content":{"rendered":"<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"\/blog\/images\/qa-run-script-periodically.webp\" style=\"margin-bottom:20px;\" title=\"How do I run my Script As a Windows Service but only only during Working Hours?\" alt=\"How do I run my Script As a Windows Service but only during Working Hours?\" 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 recently bought a license for <a href=\"\/products\/AlwaysUp\/\">AlwaysUp<\/a>. I used it to install several scripts as Windows Services.<\/p>\n<p>Most of my scripts run one time per day, and those are fine. But I have others that must run every 30 minutes &mdash; between 8:00 AM and 7:00 PM, Monday to Friday. How do I get my scripts to work like that in AlwaysUp?<\/p>\n<p align=\"right\">&mdash; Jasaf<\/p>\n<\/div>\n<p>Hi Jasaf.<\/p>\n<p>There are a couple of steps you should take run your scripts exactly when you want to.<\/p>\n<h2 class=\"blog-caption-numbered\">1. Configure AlwaysUp to run your script every 30 minutes<\/h2>\n<p>By default, AlwaysUp runs your script 24\/7, launching it at boot and quickly restarting it whenever it stops. But that&#8217;s clearly not what you want.<\/p>\n<p>To run your script every 30 minutes, on the hour and half-hour:<\/p>\n<ol style=\"margin-bottom:24px\">\n<li>\n<p>Edit your script in AlwaysUp<\/p>\n<\/li>\n<li>\n<p>Switch to the <b>Restart<\/b> tab. These settings determine what AlwaysUp does after your script exits.<\/p>\n<\/li>\n<li>\n<p>Since you don&#8217;t want to restart your script immediately after it completes, select the <b>Not immediately<\/b> option.<\/p>\n<\/li>\n<li>\n<p>Choose <b>On the next hour and half-hour<\/b>.<\/p>\n<\/li>\n<li>\n<p>Check <b>Minimize event logging as the application stops &amp; restarts<\/b>. That option tells AlwaysUp that frequent stops and starts are normal and shouldn&#8217;t cause panic. \ud83d\ude42<\/p>\n<\/li>\n<li>\n<p>Save your changes.<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/set-script-to-run-every-30-minutes.png\" class=\"zoomPopup\" title=\"Set your script to run every 30 minutes\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/set-script-to-run-every-30-minutes.png\" title=\"Set your script to run every 30 minutes (click to enlarge)\" alt=\"Set your script to run every 30 minutes\" border=\"0\" \/><\/a><\/div>\n<\/li>\n<\/ol>\n<p>At this point, you should test your AlwaysUp entry and confirm that it behaves correctly. Once started, the script should run at the top and the bottom of the hour.<\/p>\n<p>For example, we set up a batch file service as above. After an initial run, the state switched to &#8220;Waiting&#8221;. And clicking the clock icon showed AlwaysUp holding off until 3:30 for the next run (as expected):<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-script-waiting-to-run.png\" class=\"zoomPopup\" title=\"AlwaysUp is waiting to run the script\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-script-waiting-to-run.png\" title=\"AlwaysUp is waiting to run the script (click to enlarge)\" alt=\"AlwaysUp is waiting to run the script\" border=\"0\" width=\"520\" \/><\/a><\/div>\n<h2 class=\"blog-caption-numbered\">2. Use Service Scheduler to control when your AlwaysUp service runs<\/h2>\n<p>So your script is now set to run every half-hour. Great! However, AlwaysUp will run it all day, every day &mdash; weekends included.<\/p>\n<p>To make sure that your script runs only Monday through Friday between 8 AM and 7 PM:<\/p>\n<ol style=\"margin-bottom:24px\">\n<li>\n<p>Download our free <a href=\"\/products\/ServiceScheduler\/\">Service Scheduler<\/a> utility. (You can setup the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Windows_Task_Scheduler\" target=\"_blank\" rel=\"noopener\">Windows Task Scheduler<\/a> instead, but Service Scheduler is much easier to use.)<\/p>\n<\/li>\n<li>\n<p>Start Service Scheduler.<\/p>\n<\/li>\n<li>\n<p>Select <b>Service Task &gt; New<\/b> from the menu.<\/p>\n<\/li>\n<li>\n<p>Configure the <b>Add Service Task<\/b> window to start your AlwaysUp-created service every weekday at 8 AM. The window should look like this:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/start-service-every-weekday.png\" class=\"zoomPopup\" title=\"Start your \" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/start-service-every-weekday.png\" title=\"AlwaysUp is waiting to run the script (click to enlarge)\" alt=\"AlwaysUp is waiting to run the script\" border=\"0\" \/><\/a><\/div>\n<p>Note that the name of the service will be <b>whatever you called your script in AlwaysUp, plus the &#8220;(managed by AlwaysUpService)&#8221; suffix<\/b>. For example, our AlwaysUp entry is named &#8220;Process Folder Script&#8221; so the corresponding service is called &#8220;Process Folder Script (managed by AlwaysUpService)&#8221;. And that&#8217;s what we selected in the screenshot above.\n<\/li>\n<li>\n<p>Click <b>Save<\/b> to create the new service task.<\/p>\n<\/li>\n<li>\n<p>Finally, create another service task that stops the same service every weekday at 7 PM:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/stop-service-every-weekday.png\" class=\"zoomPopup\" title=\"Start your \" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/stop-service-every-weekday.png\" title=\"AlwaysUp is waiting to run the script (click to enlarge)\" alt=\"AlwaysUp is waiting to run the script\" border=\"0\" \/><\/a><\/div>\n<\/li>\n<li>\n<p>You should end up with a couple of tasks in Service Scheduler:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/service-scheduler-tasks.png\" class=\"zoomPopup\" title=\"Start your \" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/service-scheduler-tasks.png\" title=\"AlwaysUp is waiting to run the script (click to enlarge)\" alt=\"AlwaysUp is waiting to run the script\" border=\"0\" width=\"520\" \/><\/a><\/div>\n<\/li>\n<\/ol>\n<p style=\"margin-top: 30px\">\nAnd that&#8217;s it. Going forward, AlwaysUp will run your script every 30 minutes, but only on weekdays between 8 AM and 7 PM.\n<\/p>\n<p>Enjoy!<\/p>\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\/alwaysup\/turbocharge-windows-services\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Turbocharge your Applications Running as Windows Services with AlwaysUp\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/turbocharge-windows-service-thumbnail.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\">Turbocharge your Applications Running as Windows Services with AlwaysUp<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/trinium-replaces-task-scheduler\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Customer Spotlight\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/cusomer-spotlight-150x150.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\">&quot;We replaced Windows Task Scheduler with AlwaysUp and never looked back!&quot;<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/rename-service\/\"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 Rename my Application\/Service in AlwaysUp?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/rename-150x150.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 Rename my Application\/Service in AlwaysUp?<\/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 recently bought a license for AlwaysUp. I used it to install several scripts as Windows Services. Most of my scripts run one time per day, and those are fine. But I have others that must run every 30 minutes &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/run-script-service-periodically\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":11500,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[26,127,142,292],"class_list":["post-11486","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-alwaysup","tag-alwaysup-tag","tag-qa","tag-script","tag-service-scheduler"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/11486","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=11486"}],"version-history":[{"count":14,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/11486\/revisions"}],"predecessor-version":[{"id":11664,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/11486\/revisions\/11664"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/11500"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=11486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=11486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=11486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}