Running a Batch File at a Scheduled Time

by Barry Dysert
(last updated November 17, 2017)

1

It's a simple matter to have a batch file run at a scheduled time. In fact, you can run any program you wish at a scheduled time. You use the Task Scheduler, which is a utility built into Windows that allows you to schedule tasks. How you start the Task Scheduler depends on the version of Windows you are using.

  • If you are using Windows 7, you can start the Task Scheduler by choosing Start | All Programs | Accessories | System Tools | Task Scheduler.
  • If you are using Windows 8 or Windows 10, start the Task Scheduler by simply clicking the Task Scheduler option on the Start screen (Windows 8) or the Start menu (Windows 10). (This option is visible if you've turned on the display of Administrative Tools.)

Once started, click the Task Scheduler Library option in the left pane. (See Figure 1.)

Figure 1. The Task Scheduler main screen.

The main screen is essentially broken down into four areas. There is a vertical pane on the left which serves as a navigation pane if you separate your tasks into different folders. There is a vertical pane on the right which contains two areas. The top one gives you access to Actions that can be performed on the navigation item selected in the left pane. The bottom area of the right vertical pane gives you access to actions that can be performed on the task that's selected in the middle area of the screen.

This middle area is the fourth area and it, too, is broken into two horizontal areas. The top horizontal area lists the names of the scheduled tasks, their status, what triggers them, and several other items. The bottom horizontal area shows the details of whatever task is selected above.

Let's say that you want to create a task to run a batch file to synchronize two folders, and that you want this task run every day at 2:00 am. You start by clicking the "Create Basic Task" option in the top area of the right vertical pane. This launches the Create Basic Task wizard, where you can start to fill in your information. (See Figure 2.)

Figure 2. The Create Basic Task Wizard dialog box.

When supplying a name and description for the task, it is the name that is key. (It is mandatory, while the description is optional.) Try to make the name of your task as descriptive as possible, especially within the first several characters. This is so that you'll later be able to easily find it from the Task Scheduler's main screen.

After filling in the name and description, click the Next button, which takes you to step 2. (See Figure 3.)

Figure 3. Creating a basic task, step 2.

Step 2 is to define what will trigger your task to start. You have choices among several types of triggers. You can trigger your task based on a schedule (Daily, Weekly, Monthly, or One Time), when the computer starts, when a user logs on to the system, or when a particular event is logged in the system event log. Since I want my task to run every day at 2:00 am, I choose the Daily radio button.

Clicking Next at this point takes you to the third step of the wizard. (See Figure 4.)

Figure 4. Creating a basic task, step 3.

Here you are prompted for the criteria specific to whatever trigger you chose. Since I chose "Daily," I am prompted for the date/time of when the task should start, as well as how often it should recur.

Clicking Next again proceeds to the fourth step of the wizard. This is where you specify exactly what you want the task to do. (See Figure 5.)

Figure 5. Creating a basic task, step 4.

In this particular case, I want to run a batch file, which is simply viewed as a program by Windows. Thus, I need to choose the "Start a Program" option, and then click Next. (See Figure 6.)

Figure 6. Creating a basic task, step 5.

In this step you are asked for the details of the program you're going to run. The "program" I'm going to run is the batch file named "sync.bat", which is located in the "C:\bat" folder. I specify that information in the "Program/Script" box. Since this batch file is designed to synchronize two folders, I specify the names of the two folders as arguments. These will be passed to sync.bat as %1 and %2.

When you click Next one last time, you're presented with a summary screen that reminds you of what all you picked in the process of going through the wizard. (See Figure 7.)

Figure 7. Creating a basic task, step 6.

Click the Finish button and you'll be taken back to the main screen, where you'll see your task ready to run at the appointed time.

 This tip (13223) applies to Windows 7, 8, and 10.

Author Bio

Barry Dysert

Barry has been a computer professional for over 30 years, working in different positions such as technical team leader, project manager, and software developer.  He is currently a senior software engineer with an emphasis on developing custom applications under Microsoft Windows. ...

MORE FROM BARRY

Enabling Libraries in File Explorer

Windows 7 introduced us to libraries, but they're turned off in Windows 10. Here's how to get them back.

Discover More

Clearing Your Jump Lists

Ever since their introduction in Windows 7, I've found Jump lists to be great timesavers. Some people have privacy concerns ...

Discover More

How to Run a Program when Windows Starts

It's easy to have a program run when Windows starts. In fact, by using the Task Scheduler, you can have all sorts of things ...

Discover More
More WindowsTips

Using the SHIFT Statement

Sometimes your batch file needs to accept an unknown number of parameters. This is easy to deal with if you know about the ...

Discover More

PowerShell Input and Output

When dealing with a scripting language like PowerShell, one of the first things you need to learn is how to get data into and ...

Discover More

Using the FOR Statement

In another tip we were introduced to the various FOR loops that exist in Windows. The actual use of these loops was left as ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WindowsTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine minus 3?

2014-09-08 07:13:51

Brian Hershman

In Windows 7 there are some circumstances in which creation of a scheduled task requires a user password. As a user password could be dispensed with at logon to Windows 7 and earlier, that made the creation difficult but apparently not impossible even if there is no user password.
The above tip does work correctly in Windows 7, probably - I suspect - if the "Open the Properties dialog" is NOT checked.


Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WindowsTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.