SEARCH

How-To Geek

How to Create, Modify and Delete Scheduled Tasks from the Command Line

Windows XP/Server 2003 introduced us to the SchTasks command line tool which usurped the At tool offered in Windows 2000. This tool offers the ability to control every aspect of your Scheduled Tasks through calls to this command.

While the wizard Windows uses to help you graphically create Scheduled Tasks is very good, the command line tool is ideal for situations such as:

  • Manipulate tasks in batch scripts.
  • Control and create tasks on networked machines without having to login to them.
  • Mass create/sync task across multiple machines.
  • Use in custom applications to communicate with the Task Scheduler instead of having to make API calls.

As you can probably imagine, the SchTasks command has more options than we can cover in this article so we are going to focus on showing some examples of common task configurations and what the respective task looks like in the Task Scheduler.

Examples

Create ‘My Task’ to run C:RunMe.bat at 9 AM everyday:

SchTasks /Create /SC DAILY /TN “My Task” /TR “C:RunMe.bat” /ST 09:00

image

image

Modify ‘My Task’ to run at 2 PM:

SchTasks /Change /TN “My Task” /ST 14:00

image

image 

Create ‘My Task’ to run C:RunMe.bat on the first of every month:

SchTasks /Create /SC MONTHLY /D 1 /TN “My Task” /TR “C:RunMe.bat” /ST 14:00

image

image

Create ‘My Task’ to run C:RunMe.bat every weekday at 2 PM:

SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN “My Task” /TR “C:RunMe.bat” /ST 14:00

image

image

Delete the task named ‘My Task’:

SchTasks /Delete /TN “My Task”

image

Note: this will raise a warning which you will need to confirm.

Bulk Creation

Like any other command line tool, you can include multiple instructions in a batch file to accomplish bulk creation (or deletion).

For example, this script:

SchTasks /Create /SC DAILY /TN “Backup Data” /TR “C:Backup.bat” /ST 07:00
SchTasks /Create /SC WEEKLY /D MON /TN “Generate TPS Reports” /TR “C:GenerateTPS.bat” /ST 09:00
SchTasks /Create /SC MONTHLY /D 1 /TN “Sync Database” /TR “C:SyncDB.bat” /ST 05:00

Produces these tasks:

image

The ability to do this is a quick way to roll out new tasks or change existing schedules to many machines at once. As a way to ensure the tasks are updated, you could include the appropriate SchTasks commands in a domain login script which will update user machines when they log in.

Microsoft Documentation on SchTasks Command

Jason Faulkner is a developer and IT professional who never has a hot cup of coffee far away. Interact with him on Google+

  • Published 10/4/10

Comments (4)

  1. sfcg

    You can also use ‘at’ at the command line for scheduling tasks. We use it at my work to schedule syncronization between our application servers and finance DB.
    ——————————————————————————————————————————–
    The AT command schedules commands and programs to run on a computer at
    a specified time and date. The Schedule service must be running to use
    the AT command.

    AT [\computername] [ [id] [/DELETE] | /DELETE [/YES]]
    AT [\computername] time [/INTERACTIVE]
    [ /EVERY:date[,...] | /NEXT:date[,...]] “command”

    \computername Specifies a remote computer. Commands are scheduled on the
    local computer if this parameter is omitted.
    id Is an identification number assigned to a scheduled
    command.
    /delete Cancels a scheduled command. If id is omitted, all the
    scheduled commands on the computer are canceled.
    /yes Used with cancel all jobs command when no further
    confirmation is desired.
    time Specifies the time when command is to run.
    /interactive Allows the job to interact with the desktop of the user
    who is logged on at the time the job runs.
    /every:date[,...] Runs the command on each specified day(s) of the week or
    month. If date is omitted, the current day of the month
    is assumed.
    /next:date[,...] Runs the specified command on the next occurrence of the
    day (for example, next Thursday). If date is omitted, the
    current day of the month is assumed.
    “command” Is the Windows NT command, or batch program to be run.

  2. medhat

    good work
    Thank you :)

  3. Carl G

    So where can i find more information on this part “•Control and create tasks on networked machines without having to login to them”?

    I am looking to reset passwords on tasks without logging into the machine.

  4. Jason Faulkner

    @Carl G – See the help information provided by the tool for changing tasks on remote systems:

    SchTasks /Change /?

    The /RP switch allows you to change the password associated with user name the task runs as.

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!