schtasks | new in WS2003 |
Schedules tasks (commands or programs) to run on a computer at a specified time/date and manages scheduled tasks.
|
General syntax:
schtasks / command switches [/s Computer [/u [ Domain \] User [/p Password ]]]
Syntax for each type of command:
schtasks /create /sc ScheduleType /tn TaskName /tr TaskRun [/ru {[ Domain \] User SYSTEM}] [/rp Password ] [/mo Modifier ] [/d Day [, Day ...] *] [/m Month [, Month ...]] [/i IdleTime ] [/st StartTime ] [/ri Interval ] [{/et EndTime /du Duration } [/k]] [/sd StartDate ] [/ed EndDate ] [/it] [/z] [/f] schtasks /change /tn TaskName [/ru {[ Domain \] User SYSTEM}] [/rp Password ] [/tr TaskRun ] [/st StartTime ] [/ri Interval ] [{/et EndTime /du Duration } [/k]] [/sd StartDate ] [/ed EndDate ] [/{ENABLE DISABLE}] [/it] [/z] schtasks /run /tn TaskName schtasks /end /tn TaskName schtasks /delete /tn { TaskName *} [/f] schtasks [/query] [/fo {TABLE LIST CSV}] [/nh] [/v]
Here are the commands for schtasks :
Creates a scheduled task
Modifies properties of a scheduled task
Runs a scheduled task immediately
Stops a running task
Deletes a scheduled task
Displays all scheduled tasks (can omit /query )
The remaining switches for schtasks are:
Type of schedule, choose from:
Gives the task a name (in quotation marks if there are spaces).
The full path program, script, batch file, or command to run (if path is omitted, defaults to \System32 directory).
The /s switch specifies the name or IP address of the remote computer on which the scheduled task should run (if omitted, defaults to local computer). The /u and /p switches run schtasks using the specified credentials (if omitted, defaults to currently logged-on user on local computer). Note that the specified credentials are used for both scheduling and running the taskif desired you can run the task with different credentials by using the /ru switch.
Runs the task using the specified credentials (if omitted, defaults to currently logged-on user on local computer or credentials specified by /u switch if present). Unlike the /u switch, which can schedule tasks only on remote computers, the /ru switch can schedule tasks on both the local and remote computers.
How often a scheduled task runs. Values defined by /sc set the schedule for how the task runs, e.g., hourly. Modifier describes how frequently it runs; every hour (i.e., Modifier of 1, which is the default), every 2 hours ( Modifier of 2), and so on. Allowed values for Modifier are:
Every N minutes (1-1439)
Every N hours (1-23)
Every N days (1-365)
Every N weeks (1-52)
Only once
Every time the system starts
Every time a user logs on
When the system has been idle for number of minutes specified by /i switch
Every N months (1-12)
LASTDAY (run on the last day of the month)
FIRST, SECOND, THIRD, FOURTH, LAST (requires /d Day switch)
Specifies one or more days of the week/month when WEEKLY or MONTHLY is used. Allowed values for Day are:
MON-SUN[, MON-SUN...] * (if omitted, defaults to MON , while wildcard (*) means every day)
1-31 (if omitted, defaults to 1)
MON-SUN
One or more months during which the scheduled task runs (select from JAN to DEC or use * for every month). Works only with MONTHLY and, if omitted, defaults to * (every month).
Number of minutes computer must be idle before task starts (select from 1 to 999). Works only with ONIDLE .
Specifies the time of day that the task starts (each time it starts) in HH:MM 24-hour format. The default value is the current time on the local computer. The /st parameter is valid with MINUTE , HOURLY , DAILY , WEEKLY , MONTHLY , and ONCE schedules. It is required for a ONCE schedule.
Repetition interval in minutes (select from 1 to 599,940 minutes). Doesn't apply for MINUTE , HOURLY , ONSTART , ONLOGON , or ONIDLE , and defaults to 10 minutes if /e t or /du are used.
Time of day in HH:MM 24-hour format that a MINUTE or HOURLY task schedule ends (if omitted, defaults to no end time)
Maximum time interval in HHHH:MM 24-hour format for a MINUTE or HOURLY schedule (if omitted, defaults to no maximum duration).
Kills the program associated with the task at time specified by /et or /du (if omitted, schtasks doesn't restart program again when it reaches the time specified by /et or /du , and it doesn't stop the program if it's still running).
Date when task schedule starts (if omitted, defaults to current date on local computer). Format for date depends on Regional and Language Options in the Control Panel on local computer, for instance, MM/DD/YYYY for English (United States).
Date when task schedule ends (if omitted, no ending date). Format for date depends on Regional and Language Options in the Control Panel on local computer, for instance, MM/DD/YYYY for English (United States).
Runs the task only if the user account under which the task runs is logged on to the computer (has no effect if task runs with SYSTEM identity). This user account is either:
The current user on the local computer when the task was scheduled
The account specified by the /u parameter
The account specified by the /ru parameter
Delete the task once its schedule is completed.
Create the task and suppress warnings even if the task already exists.
Format for displaying tasks (if omitted, default is TABLE ).
Omits header row from displayed information if /fo is set to TABLE or CSV .
Displays verbose information.
Table 5-23 summarizes which switches are allowed for each ScheduleType parameter.
ScheduleType | Allowed switches | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
/mo | d | /m | /i | /st | /ri | /et | /du | /k | /sd | /e | |
MINUTE |
|
|
|
|
|
|
|
|
|
|
|
HOURLY |
|
|
|
|
|
|
|
|
|
|
|
DAILY |
|
|
|
|
|
|
|
|
|
|
|
WEEKLY |
|
|
|
|
|
|
|
|
|
|
|
MONTHLY |
|
|
|
|
|
|
|
|
|
|
|
ONCE |
|
|
|
|
|
|
|
|
|
|
|
ONSTART |
|
|
|
|
|
|
|
|
|
|
|
ONLOGON |
|
|
|
|
|
|
|
|
|
|
|
ONIDLE |
|
|
|
|
|
|
|
|
|
|
|
Schedule the script testscript.vbs located in \System32 to run every five minutes:
schtasks /create /sc minute /mo 5 /tn "First Task" /tr testscript.vbs The task will be created under current logged-on usernames ("MTIT\Administrator"). Please enter the run as password for MTIT\Administrator: ******** SUCCESS: The scheduled task "First Task" has successfully been created.
Schedule the script to run every 2 hours for 12 hours starting at midnight:
schtasks /create /sc hourly /mo 2 /tn "Second Task" /tr testscript.vbs /st 00:00 /du 0012:00 /ru MTIT\Administrator /rp Passw0rd SUCCESS: The scheduled task "Second Task" has successfully been created.
Schedule the script to run daily at 6 a.m. until June 30, 2005:
schtasks /create /sc daily /tn "Third Task" /tr testscript.vbs /st 06:00 /ed 06/30/2005 /ru MTIT\Administrator /rp Passw0rd SUCCESS: The scheduled task "Third Task" has successfully been created.
Schedule the script to run every Monday:
schtasks /create /sc weekly /tn "Fourth Task" /tr testscript.vbs /d MON /ruMTIT\Administrator /rp Passw0rd SUCCESS: The scheduled task "Fourth Task" has successfully been created.
Schedule the script to run on the last day of each month:
schtasks /create /sc monthly /tn "Fifth Task" /tr testscript.vbs /mo lastday /m * /ru MTIT\Administrator /rp Passw0rd SUCCESS: The scheduled task "Fifth Task" has successfully been created.
Display scheduled tasks in table format:
schtasks /query TaskName Next Run Time Status = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Fifth Task 3:31:00 PM, 3/31/2003 First Task 3:35:00 PM, 3/27/2003 Fourth Task 3:28:00 PM, 3/31/2003 Second Task 12:00:00 AM, 3/28/2003 Third Task 6:00:00 AM, 3/28/2003
List scheduled tasks using verbose option:
C:\>schtasks /query /fo list /v HostName: ESRV210D TaskName: Fifth Task Next Run Time: 3:31:00 PM, 3/31/2003 Status: Logon Mode: Interactive/Background Last Run Time: Never Last Result: 0 Creator: Administrator Schedule: At 3:31 PM on day 31 of every month, starting 3/27/2003 Task To Run: C:\WINDOWS\system32\testscript.vbs Start In: testscript.vbs Comment: N/A Scheduled Task State: Enabled Scheduled Type: Monthly Start Time: 3:31:00 PM Start Date: 3/27/2003 End Date: N/A Days: 31 Months: JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC Run As User: MTIT\Administrator Delete Task If Not Rescheduled: Disabled Stop Task If Runs X Hours and X Mins: 72:0 Repeat: Every: Disabled Repeat: Until: Time: Disabled Repeat: Until: Duration: Disabled Repeat: Stop If Still Running: Disabled Idle Time: Disabled Power Management: No Start On Batteries, Stop On Battery Mode HostName: ESRV210D TaskName: First Task etc...
Delete the task named "Fifth Task":
schtasks /delete /tn "Fifth Task" WARNING: Are you sure you want to remove the task "Fifth Task" (Y/N )? y SUCCESS: The scheduled task "Fifth Task" was successfully deleted.
Run the task named "First Task" immediately:
schtasks /run /tn "First Task" SUCCESS: Attempted to run the scheduled task "First Task".
Kill the program just started:
schtasks /end /tn "First Task" SUCCESS: The scheduled task "First Task" has been terminated successfully.
Disable "Third Task" to temporarily prevent it from running:
schtasks /change /tn "Third Task" /disable /ru MTIT\Administrator /rp Password SUCCESS: The parameters of scheduled task "Third Task" have been changed.
The user account specified by the /u switch must belong to the Administrators group on the remote computer specified by the /s switch, and the local computer must belong to the same domain as the remote computer or be in a domain trusted by the remote computer's domain. In other words, only Administrators can schedule tasks. You can however specify that the program started by the scheduled task should run under different credentials (even non-Administrator credentials) by using the /ru switch.
If you use /ru SYSTEM , you don't need to use /rp to specify a password.
If you run a task using System credentials, users will not be able to view or interact with the program started by the task. This is because System doesn't have interactive logon rights.
schtasks doesn't verify the program filename or password for a user account specified by /u , and if either of these is wrong the task simply won't run.
To check for errors in running scheduled tasks, view the SchedLgU.txt log file in the \Windows directory.
schtasks works the same as Scheduled Tasks in the Control Panel.
at , Tasks