Friday, May 6, 2016

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

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.
Source: http://www.howtogeek.com/51236/how-to-create-modify-and-delete-scheduled-tasks-from-the-command-line/

No comments:

Post a Comment