Pages

Monday, August 15, 2005

HOW TO: Use Schtasks.exe to Schedule Tasks in Windows Server 2003

Re found this while looking into a problem with remote AT job scheduling on Win2k3. Seems they changed the command a bit:

HOW TO: Use Schtasks.exe to Schedule Tasks in Windows Server 2003
View products that this article applies to.
Article ID : 814596
Last Review : April 12, 2004
Revision : 1.0
On This Page
SUMMARY
Overview of the Schtasks.exe Tool
Syntax and Parameters
How to Create a Scheduled Task
How to Change a Scheduled Task
How to Run a Scheduled Task
How to End a Scheduled Task
How to Delete a Scheduled Task
How to Perform a Query of Scheduled Tasks
MORE INFORMATION
APPLIES TO

SUMMARY
In Windows Server 2003, you can use Scheduled Tasks in Control Panel to create, delete, configure, or display scheduled tasks. You can also use Schtasks.exe to schedule tasks manually.


Back to the top

Overview of the Schtasks.exe Tool
Schtasks schedules commands and programs to run periodically or at a specific time. Schtasks adds and removes tasks from the schedule, starts and stops tasks on demand, and displays and changes scheduled tasks.


Back to the top

Syntax and Parameters
The following is a list of the syntax and parameters that you can use with Schtasks.exe: • Schtasks /Create
Creates a new scheduled task. • Syntax:
schtasks /create/tn TaskName /tr TaskRun /sc schedule [/mo modifier] [/d day] [/m month[,month...] [/i IdleTime] [/st StartTime] [/sd StartDate] [/ed EndDate] [/du duration] [/s computer [/u [domain\]user /p password]] [/ru {[Domain\]User | "System"} [/rp Password]] /?
• Parameters: • /tn TaskName Specifies a name for the task.
• /tr TaskRun Specifies the program or command that the task runs. Type the fully qualified path and file name of an executable file, script file, or batch file. If you omit the path, Schtasks.exe assumes that the file is in the Systemroot\System32 folder.
• /sc schedule Specifies the schedule type. Valid values are MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE.
• /mo modifier Specifies how frequently the task runs in its schedule type. This parameter is required for a MONTHLY schedule. This parameter is valid, but optional, for a MINUTE, HOURLY, DAILY, or WEEKLY schedule. The default value is 1.
• /d day Specifies a day of the week or a day of a month. Valid only with a WEEKLY or MONTHLY schedule.
• /m month[,month...] Specifies a month of the year. Valid values are JAN - DEC and * (every month). The /m parameter is valid only with a MONTHLY schedule. It is required when the LASTDAY modifier is used. Otherwise, it is optional and the default value is * (every month).
• /i IdleTime Specifies how many minutes the computer is idle before the task starts. Type a whole number from 1 to 999. This parameter is valid only with an ONIDLE schedule, and then it is required.
• /st StartTime Specifies the time of day that the task starts in HH:MM:SS 24-hour format. The default value is the current local time when the command completes. The /st parameter is valid with MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, and ONCE schedules. It is required with a ONCE schedule.
• /sd StartDate Specifies the date that the task starts in MM/DD/YYYY format. The default value is the current date. The /sd parameter is valid with all schedules, and is required for a ONCE schedule.
• /ed EndDate Specifies the last date that the task is scheduled to run. This parameter is optional. It is not valid in a ONCE, ONSTART, ONLOGON, or ONIDLE schedule. By default, schedules have no ending date.
• /du Duration Specifies a maximum length of time for a minute or hourly schedule in the HHHH:MM 24-hour format. After the specified time elapses, Schtasks does not start the task again until the start time happens again. By default, task schedules have no maximum duration. This parameter is optional and valid only with a MINUTE or HOURLY schedule.
• /s Computer Specifies the name or IP address of a remote computer, with or without backslash characters. The default is the local computer.
• /u [domain\]user Runs the command with the permissions of the specified user account. By default, the command runs with the permissions of the user who is logged on to the computer that is running Schtasks.
• /p password Specifies the password of the user account that you specified in the /u parameter. This parameter is required when the /u parameter is used.
• /ru {[Domain\]User | "System"} Runs the tasks with the permission of the specified user account. By default, the task runs with the permissions of the user who is logged on to the computer that is running Schtasks.
• /rp Password Specifies the password of the user account that is specified in the /ru parameter. If you omit this parameter when you specify a user account, Schtasks.exe prompts you for the password and obscures the text you type. Tasks that run with permissions of the NT Authority\System account do not require a password and Schtasks.exe does not prompt for one.
• /? Displays help at the command prompt.


back to the top
• Schtasks /Change
Changes one or more of the following properties of a task: • The program that the task runs (/tr ).
• The user account under which the task runs (/ru ).
• The password for the user account (/rp ).
• Syntax:schtasks /change /tn TaskName [/s computer [/u [domain\]user /p password]] [/tr TaskRun] [/ru [Domain\]User | "System"] [/rp Password]
• Parameters: • /tn TaskName Identifies the task to be changed. Type the task name.
• /s Computer Specifies the name or IP address of a remote computer with or without backslash characters. The default is the local computer.
• /u [domain\]user Runs the command with the permissions of the specified user account. By default, the command runs with the permissions of the user who is logged on to the computer that is running Schtasks.
• /p password Specifies the password of the user account that you specified in the /u parameter. This parameter is required when the /u parameter is used.
• /tr TaskRun Changes the program that the task runs. Type the fully qualified path and file name of an executable file, script file, or batch file. If you omit the path, Schtasks.exe assumes that the file is in the Systemroot\System32 folder. The specified program replaces the original program that is run by the task.
• /ru [Domain\]User | "System" Changes the user account for the task.
• /rp Password Changes the account password for the task. Type the new password.
• /? Displays help at the command prompt.


back to the top
• Schtasks /Run
Starts a scheduled task immediately. The run operation ignores the schedule, but uses the program file location, user account, and password that are saved in the task to run the task immediately. • Syntax:schtasks /run /tn TaskName [/s computer [/u [domain\]user /p password]] /?
• Parameters: • /tn TaskName Identifies the task. This parameter is required.
• /s Computer Specifies the name or IP address of a remote computer with or without backslash characters. The default is the local computer.
• /u [domain\]user Runs the command with the permissions of the specified user account. By default, the command runs with the permissions of the user who it logged on to the computer that is running Schtasks.
• /p password Specifies the password of the user account that you specified in the /u parameter. This parameter is required when the /u parameter is used.
• /? Displays help at the command prompt.

back to the top
• Schtasks /End
Stops a program that was started by a task. • Syntax: schtasks /end /tn TaskName [/s computer [/u [domain\]user /p password]] /?

• Parameters: • /tn TaskName Identifies the task that started the program. This parameter is required.
• /s Computer Specifies the name or IP address of a remote computer with or without backslash characters. The default is the local computer.
• /u [domain\]user Runs the command with the permissions of the specified user account. By default, the command runs with the permissions of the user who is logged on to the computer that is running Schtasks.
• /p password Specifies the password of the user account that is specified in the /u parameter. This parameter is required when the /u parameter is used. /? Displays help.

back to the top
• Schtasks /Delete
Deletes a scheduled task. • Syntax:schtasks /delete /tn {TaskName | *} [/f ] [/s computer [/u [domain\]user/p password]] [/? ]

• Parameters: • /tn {TaskName | *} Identifies the task being deleted. This parameter is required. • TaskName Deletes the named task.
• * Deletes all the scheduled tasks on the computer.

• /f Suppresses the confirmation message. The task is deleted without warning.
• /s Computer Specifies the name or IP address of a remote computer with or without backslash characters. The default is the local computer.
• /u [domain\]user Runs the command with the permissions of the specified user account. By default, the command runs with the permissions of the user who is logged on to the computer that is running Schtasks.
• /p password Specifies the password of the user account that you specified in the /u parameter. This parameter is required when the /u parameter is used.
• /? Displays help at the command prompt.


back to the top
• Schtasks /Query
Displays all the tasks that are scheduled to run on the computer, including those that are scheduled by other users: • Syntax:schtasks [/query] [/fo {TABLE | LIST | CSV}] [/nh ] [/v] [/s computer [/u [domain\]user/p password]]
• Parameters:[/query] The operation name is optional. Typing schtasks without any parameters performs a query.
• /fo {TABLE | LIST | CSV} Specifies the output format. TABLE is the default. /nh Omits column headings from the table display. This parameter is valid with the TABLE and CSV output formats.
• /v Adds advanced properties of the tasks to the display. Queries using /v should be formatted as LIST or CSV.
• /s Computer Specifies the name or IP address of a remote computer with or without backslash characters. The default is the local computer.
• /u [domain\]user Runs the command with the permissions of the specified user account. By default, the command runs with the permissions of the user who is logged on to the computer that is running Schtasks.
• /p password Specifies the password of the user account that is specified in the /u parameter. This parameter is required when the /u parameter is used.
• /? Displays help at the command prompt.


Back to the top

How to Create a Scheduled Task
To create a scheduled task: 1. Click Start, click Run, type cmd, and then click OK.
2. At the command prompt, type net start, and then press ENTER to display a list of currently running services. If Task Scheduler is not displayed in the list, type net start "task scheduler", and then press ENTER.
3. At the command prompt, type schtasks /create /tn "Application_Name" /tr c:\apps\Application_Name /sc Value /st HH:MM:SS /ed MM/DD/YYYY, and then press ENTER. Note that you may have to change the parameters for your situation. For example, you might type schtasks /create /tn "My App" /tr c:\apps\myapp.exe /sc daily /st 08:00:00 /ed 12/31/2004 This example schedules the MyApp program to run once a day, every day, at 8:00 A.M. until December 31, 2004. Because it omits the /mo parameter, the default interval of 1 is used to run the command every day.

Back to the top

How to Change a Scheduled Task
To change a scheduled task: 1. Click Start, click Run, type cmd, and then click OK.
2. At the command prompt, typenet start, and then press ENTER to display a list of currently running services. If Task Scheduler is not displayed in the list, type net start "task scheduler", and then press ENTER.
3. At the command prompt, typeschtasks /change /tn TaskName [/s computer [/u [domain\]user /p password]] [/tr TaskRun] [/ru [Domain\]User | "System"] [/rp Password] , and then press ENTER. Note that you may have to change the parameters for your situation. For example, to change the program that a task runs, type: schtasks /change /tn "Application_Name" /tr C:\File_Path\Application_Name.exe

Back to the top

How to Run a Scheduled Task
To manually run a scheduled task outside its schedule: 1. Click Start, click Run, type cmd, and then click OK.
2. At the command prompt, type net start, and then press ENTER to display a list of currently running services. If Task Scheduler is not displayed in the list, type net start "task scheduler", and then press ENTER.
3. At the command prompt, type schtasks /run /tn TaskName [/s computer [/u [domain\]user /p password]] , and then press ENTER. Note that you may have to change the parameters for your situation. For example, to run a task on the local computer, type schtasks /run /tn "Task_Name" .

Back to the top

How to End a Scheduled Task
To end a scheduled task: 1. Click Start, click Run, type cmd, and then click OK.
2. At the command prompt, type net start, and then press ENTER to display a list of currently running services. If Task Scheduler is not displayed in the list, type net start "task scheduler", and then press ENTER.
3. At the command prompt, type schtasks /end /tn TaskName [/s computer [/u [domain\]user /p password]] , and then press ENTER. For example, to end the instances of a program that was started by a scheduled task on a local computer, type schtasks /end /tn "Task_Name".

Back to the top

How to Delete a Scheduled Task
To delete a scheduled task: 1. Click Start, click Run, type cmd, and then click OK.
2. At the command prompt, type net start, and then press ENTER to display a list of currently running services. If Task Scheduler is not displayed in the list, type net start "task scheduler", and then press ENTER.
3. At the command prompt, type schtasks /delete /tn {TaskName | *} [/f] [/s computer [/u [domain\]user /p password]], and then press ENTER. For example, to delete all tasks scheduled for the local computer, type schtasks /delete /tn * /f.

Back to the top

How to Perform a Query of Scheduled Tasks
To perform a query of scheduled tasks: 1. Click Start, click Run, type cmd, and then click OK.
2. At the command prompt, type net start, and then press ENTER to display a list of currently running services. If Task Scheduler is not displayed in the list, type net start "task scheduler", and then press ENTER.
3. At the command prompt, type schtasks /query , and then press ENTER. Output from this example displays a table of tasks that have been scheduled to run.
For more information about how to use Schtasks.exe, search for Schtasks.exe in Windo
After the specified time elapses, Schtasks does not start the task again until the start time recurs. By default, task schedules have no maximum duration. This parameter is optional and valid only with a MINUTE or HOURLY schedule.
ws Server 2003 Help.


Back to the top

MORE INFORMATION
For further information on the Schtasks command, go to the following Microsoft Web page:

http://www.microsoft.com/resources/documentation/WindowsServ/2003/standard/proddocs/en-us/Default.asp?url=/resources/documentation/WindowsServ/2003/standard/proddocs/en-us/schtasks.asp (http://www.microsoft.com/resources/documentation/windowsserv/2003/standard/proddocs/en-us/default.asp?url=/resources/documentation/windowsserv/2003/standard/proddocs/en-us/schtasks.asp)

No comments:

Post a Comment