search
top

Creating and Managing Scheduled Tasks from the Command Line in Windows

Introduction

Scheduled tasks are a wonderful tool to use in Windows to perform repetitious tasks on the server and your system. This can be updating, backups, cleanups and many other tasks. There are many different ways using command line and the GUI to accomplish adding, changing and deleting tasks. In this post we will cover using the command line to manage and maintain scheduled tasks. Scheduled tasks are kept in the C:\Windows\System32\Tasks directory and are xml files that contain the job information.

Managing Tasks with schtasks Command

Now we are ready to dig in and start managing our tasks from the command line. Microsoft has provided a way to do this with the schtasks command.

Step 1 – How To Create a Scheduled Task

If you are logged into the same computer where you want to run the scheduled task, then you can use the below command to create the task.

schtasks create /RU username /RP password /SC schedule_frequency /MO Schedule_modifier /D days /M months /TN taskname /TR Task_command /ST start_time /SD start_day /ED end_date

Now let’s see few examples.

Example 1: Schedule disk defragmentation on every Saturday at 6AM. User credentials are administrator/password.

If the specified username and password are correct, then you would get the below message when you run the above command.

If the credentials are not correct, you may get a warning like below.

If there exists a scheduled task with the same name then the error would be:

If you need to use a domain user account to run the task you can specify domainname\username with /RU option.

You can also create a scheduled task to run as system with the following syntax.

Here we are creating a daily task run a script at 4:15 am running as SYSTEM.

Step 2 – How to get the list of scheduled tasks

Just run Schtasks command and you can see the list of scheduled commands.

If you want complete details about each of the tasks you can run the command ‘Schtasks /query /v

Step 3 – Delete a scheduled task

We can delete a schedule task using ‘schtasks /delete /TN task_name‘ command. For example, to delete the task we created in the example 1 we can run the below command.

Delete all the scheduled tasks

You can run the below command to delete all the scheduled tasks.

Step 4 – Disable a scheduled task

There does not seem to be a way to disable a scheduled task from command line. We can delete the tasks as mentioned above.

Step 5 – Modify a scheduled task

We can change a scheduled task using ‘schtasks /change’ command. Run ‘schtasks /change /?’ for the syntax.

Bonus – Create a Folder with Scheduled Tasks

Now for a bit of organization. Say you have many tasks and you would like to group them in folders.

This creates a new task folder called Admin and creates a new task MyTask under the new folder

If the task needs to get created under an existing folder, try

This creates a new task My New Task under an existing task folder Existing Task Folder

Conclusion

As we can see the schtasks command allows us to manage Scheduled Tasks in Windows easily in creating, deleting, modifying and organizing tasks.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

top