Task scheduler - Run a task every hour after startup

By xngo on March 18, 2020

In MS Windows, you can use the Task scheduler to run a task at startup for an interval of time forever. In the example below, I put the following codes in the echo-date-time.bat batch file:

echo %date% %time% >> c:\xuan\schedule-task-output.txt

The script will write the current date and time to c:\xuan\schedule-task-output.txt. Here are the steps to create a task in the Task scheduler to run the script at startup and for every hour.

  1. Open the Task Scheduler.
  2. Create a task.
  3. On the General tab,
    • Enter the task name.
    • Select Run whether user is logged on or not. You will need the Administrator password.
    • Select Run with highest privileges in case your task requires Administrator privilege to run.
      MS Win - Task Scheduler - General tab
  4. On the Trigger tab, set to begin the task at startup and repeat the task every 1 hour and indefinitely.
    MS Win - Task Scheduler - Trigger tab
  5. On the Action tab, set your program/script. If your program requires input parameters, then add them in Add arguments (optional) input field. For my case, it is echo-date-time.bat.
    MS Win - Task Scheduler - Action tab

Caveat

If you set your Trigger to begin the task At startup, then that task will NOT run until you restart your computer. It doesn't matter if you manually force the task to run now, it will not run. Even though the Status is set to Running, it doesn't run because Next Run Time is empty.

MS Win - Task Scheduler - Running but no Next Run Time

For the case where you don't know when your server is going to be restarted, create a duplicate task but set the trigger to begin the task On a schedule for One time only.

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.