The Core Technologies Blog

Professional Software for Windows Services / 24×7 Operation


Q&A: How do I Run my Script as a Windows Service — but only during Working Hours?

How do I run my Script As a Windows Service but only during Working Hours?
  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 — between 8:00 AM and 7:00 PM, Monday to Friday. How do I get my scripts to work like that in AlwaysUp?

— Jasaf

Hi Jasaf.

There are a couple of steps you should take run your scripts exactly when you want to.

1. Configure AlwaysUp to run your script every 30 minutes

By default, AlwaysUp runs your script 24/7, launching it at boot and quickly restarting it whenever it stops. But that’s clearly not what you want.

To run your script every 30 minutes, on the hour and half-hour:

  1. Edit your script in AlwaysUp

  2. Switch to the Restart tab. These settings determine what AlwaysUp does after your script exits.

  3. Since you don’t want to restart your script immediately after it completes, select the Not immediately option.

  4. Choose On the next hour and half-hour.

  5. Check Minimize event logging as the application stops & restarts. That option tells AlwaysUp that frequent stops and starts are normal and shouldn’t cause panic. 🙂

  6. Save your changes.

    Set your script to run every 30 minutes

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.

For example, we set up a batch file service as above. After an initial run, the state switched to “Waiting”. And clicking the clock icon showed AlwaysUp holding off until 3:30 for the next run (as expected):

AlwaysUp is waiting to run the script

2. Use Service Scheduler to control when your AlwaysUp service runs

So your script is now set to run every half-hour. Great! However, AlwaysUp will run it all day, every day — weekends included.

To make sure that your script runs only Monday through Friday between 8 AM and 7 PM:

  1. Download our free Service Scheduler utility. (You can setup the Windows Task Scheduler instead, but Service Scheduler is much easier to use.)

  2. Start Service Scheduler.

  3. Select Service Task > New from the menu.

  4. Configure the Add Service Task window to start your AlwaysUp-created service every weekday at 8 AM. The window should look like this:

    AlwaysUp is waiting to run the script

    Note that the name of the service will be whatever you called your script in AlwaysUp, plus the “(managed by AlwaysUpService)” suffix. For example, our AlwaysUp entry is named “Process Folder Script” so the corresponding service is called “Process Folder Script (managed by AlwaysUpService)”. And that’s what we selected in the screenshot above.

  5. Click Save to create the new service task.

  6. Finally, create another service task that stops the same service every weekday at 7 PM:

    AlwaysUp is waiting to run the script
  7. You should end up with a couple of tasks in Service Scheduler:

    AlwaysUp is waiting to run the script

And that’s it. Going forward, AlwaysUp will run your script every 30 minutes, but only on weekdays between 8 AM and 7 PM.

Enjoy!

Posted in AlwaysUp | Tagged , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *