How to Schedule a Batch File in Windows

How to Schedule a Batch File in Windows? If you’re not automating things, you’re missing out on the point of computers. The real purpose of computers is to do tedious, repetitive things humans don’t want to do anymore.

Batch files are one of the best ways to automate tasks. Add on to that the ability to schedule those batch files and you’ve got a powerful productivity tool.

How to Schedule a Batch File in Windows
How to Schedule a Batch File in Windows

Scheduling Batch Files in Windows Using Task Scheduler

After you make a batch file to automate a job, you’ll want it to run regularly. The easiest way to do that is with the Task Scheduler built into Windows. It’s a tool that automatically runs jobs on a schedule.

  1. Select the Windows Start button and type scheduler. The top result should be Windows Task Scheduler
1a sched open task scheduler
How to Schedule a Batch File in Windows

Task Scheduler will have many scheduled tasks already. Windows and programs use scheduled tasks, too.

1b sched see task scheduler
How to Schedule a Batch File in Windows
  1. Make a new folder for your tasks so you don’t lose it amongst the other tasks already here. Right-click on Task Scheduler Library and select New Folder… or select New Folder in the Actions pane on the right side of the window.
2 sched new folder
How to Schedule a Batch File in Windows
  1. Enter a name for the new folder. Make it something meaningful.
3 sched name folder
How to Schedule a Batch File in Windows
  1. Right-click on the new folder and select Create Task… or select Create Task… in the Actions pane.
4 sched create task
How to Schedule a Batch File in Windows
  1. The Create Task window will open on the General tab. Enter a meaningful name for the task in the Name: field. In the Description: field, write what the task does. It’s a good idea to put the location of the script that it calls. This makes it easier to change the task and script in the future.

    Note the Change User or Group button. This allows you to run the script under a different user. If your batch file requires Administrator permissions, you should change the user to Administrator. It will ask you for the Administrator’s password, so it’s not a shortcut to take over the computer.
5 sched name desc
How to Schedule a Batch File in Windows

Also, note that the script will Run only when the user is logged on. You can change this to Run whether user is logged on or not if you want it to run anytime.

Note the other options. For most tasks, the default values are sufficient. Be aware that you can make these changes if needed.

  1. Select the Triggers tab. Triggers are what will decide when a task runs. Select New to create a trigger.
6 sched new trigger
How to Schedule a Batch File in Windows
  1. There are many options in the New Trigger window. Look around to see what your options are.
7 sched trigger details
How to Schedule a Batch File in Windows
  1. Select the basic trigger task using the Begin the tasks drop-down menu. Options include:
     
    • On a schedule
    • At log on 
    • At startup
    • On idle
    • On an event
    • At task creation/modification
    • On connection to user session
    • On disconnect from user session
    • On workstation lock
    • On workstation unlock

On a schedule is the most popular one and the one we’ll use for this exercise.

  1. There are options for scheduling Setting as well. Choices include: 
    • One time
    • Daily
    • Weekly
    • Monthly. 

We selected Daily for this example. You can also decide when the schedule starts and recurs.

  1. Under Advanced settings, you can set more parameters around how the task triggers. This task is being set to repeat every 5 minutesindefinitely. Note that the Enabled box is checked by default. This is the first place to check when troubleshooting why a scheduled task won’t run. Select OK once you’ve set up the trigger.
  2. Select the Actions tab and then New to tell the scheduled task what it’s going to do.
8 sched new actions
How to Schedule a Batch File in Windows
  1. In the drop-down menu Action: you have the choice to:
    • Start a program
    • Send an email
    • Display a message. 

The last two are deprecated and not supported options anymore. It’s best not to use them when you schedule batch files. Leave it on the default Start a program.

9 sched action details
How to Schedule a Batch File in Windows

Enter the full path to the script. Use the Browse button to go to the script, and select it.

The Add arguments and Start in fields are blank. You might use these when you progress to more complicated scripts and tasks. You’ll definitely need these to schedule PowerShell scripts. Select OK to continue.

  1. The task is scheduled. Select OK to close the window and return to the Task Scheduler. Select the task you just made and test it. Right-click on the task and select Run or select Run in the Actions pane.
11a sched run test
How to Schedule a Batch File in Windows

When the task finishes, look at the Last Run Result column. You should see The operation completed successfully.

If it says anything else, try using the F5 button to refresh the screen. If it still says anything else, there’s something wrong with your script or the way you scheduled the task. You have some troubleshooting to do.

11b sched run test successful

What About the Conditions and Settings Tabs?

Yes, there are two tabs we didn’t discuss in the above instructions. For most tasks, you don’t need to go into these tabs. There are default values set in them that generally are best left alone. Still, let’s take a look at the tabs.

Create Task – Conditions

These settings relate to the state of the computer. If the task takes a lot of resources or can interrupt the person using it, change the Idle section. 

conditions idle

The Power section defaults to having Start the task only if the computer is on AC power and Stop if the computer switches to battery power already checked.

In most cases when you schedule batch files, it’s fine to leave these checked. We set some computers to go to sleep to save power when they’re not being used. If the computer is asleep, the task won’t run. If that’s the case, you’ll want to check the Wake the computer to run this task box.

conditions power

These days, a computer is almost always connected to a network. Still, if your task depends on a solid network connection, change the Network section.

conditions network

Create Task – Settings

The Settings tab relates to the behavior of the task. That means how the task is running. The Allow task to be run on demand is checked by default. The other choices relate to situations where a task gets skipped or fails.

Some tasks may get stuck in a loop, or not run because their trigger conditions aren’t met. These are the settings you’d adjust to account for that. For most tasks, the default settings are good.

settings

What Can I Do With Scheduled Batch Files?

Once you know how to schedule tasks, the mind can race with ideas of things to automate. You can auto delete filesset favorite programs to open on login, or automatically clear the print queue of failed jobs. Whatever task you do repeatedly, you can probably script it and schedule it.

Reference: https://helpdeskgeek.com/windows-10/how-to-schedule-a-batch-file-in-windows/

Leave a Comment