schtasks | new in WS2003 |
tasks (commands or programs) to run on a computer at a specified
time/date and manages scheduled tasks.
|
Syntax
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]
Options
Here are the commands for schtasks:
- create
Creates a scheduled task- change
Modifies properties of a scheduled task- run
Runs a scheduled task immediately- end
Stops a running task- delete
Deletes a scheduled task- query
Displays all scheduled tasks (can omit /query)
The remaining switches for schtasks are:
- /sc ScheduleType
Type of schedule, choose from:- MINUTE
- HOURLY
- DAILY
- WEEKLY
- MONTHLY
- ONCE
- ONSTART
- ONLOGON
- ONIDLE
- /tn TaskName
Gives the task a name (in quotation marks if there are spaces).- /tr TaskRun
The full path program, script, batch file, or command to run (if path
is omitted, defaults to \System32 directory).- /s Computer /u [Domain\]User /p Password
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.- /ru {[Domain\]User | SYSTEM} /rp Password
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.- /mo Modifier
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:- MINUTE
Every N minutes (1-1439)- HOURLY
Every N hours (1-23)- DAILY
Every N days (1-365)- WEEKLY
Every N weeks (1-52)- ONCE
Only once- ONSTART
Every time the system starts- ONLOGON
Every time a user logs on- ONIDLE
When the system has been idle for number of minutes specified by
/i switch- MONTHLY
Every N months (1-12)LASTDAY (run on the last day of the month)FIRST, SECOND, THIRD, FOURTH, LAST (requires /d
Day switch)
- /d Day[,Day...] | *
Specifies one or more days of the week/month when
WEEKLY or MONTHLY is used.
Allowed values for Day are:- With WEEKLY
MON-SUN[, MON-SUN...] | * (if omitted, defaults to
MON, while wildcard (*) means every day)- With MONTHLY (if 1-12)
1-31 (if omitted, defaults to 1)- With MONTHLY (if FIRST, SECOND, THIRD, FOURTH, or LAST)
MON-SUN
- /m Month[,Month...]
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).- /i IdleTime
Number of minutes computer must be idle before task starts (select
from 1 to 999). Works only with ONIDLE.- /st StartTime
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.- /ri Interval
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 /et or
/du are used.- /et EndTime
Time of day in HH:MM 24-hour format that a MINUTE
or HOURLY task schedule ends (if omitted, defaults
to no end time)- /du Duration
Maximum time interval in HHHH:MM 24-hour format for a
MINUTE or HOURLY schedule (if
omitted, defaults to no maximum duration).- /k
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).- /sd StartDate
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).- /ed EndDate
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).- /it
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
- /z
Delete the task once its schedule is completed.- /f
Create the task and suppress warnings even if the task already exists.- /fo {TABLE | LIST | CSV}
Format for displaying tasks (if omitted, default is
TABLE).- /nh
Omits header row from displayed information if /fo
is set to TABLE or CSV.- /v
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 |
Examples
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.
Notes
- 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.
See Also
at, Tasks