RSS

SchTasks

25 Sep

SCHTASKS /Create [/S system [/U username [/P [password]]]]    [/RU username [/RP password]] /SC schedule [/MO modifier] [/D day]    [/M months] [/I idletime] /TN taskname /TR taskrun [/ST starttime]    [/RI interval] [ {/ET endtime | /DU duration} [/K] ]      [/SD startdate] [/ED enddate] [/IT] [/Z] [/F]

Description:
    Enables an administrator to create scheduled tasks on a local or remote system.

Parameter List:
    /S   system    Specifies the remote system to   connect to. If omitted the system   parameter defaults to the local   system.

    /U   username  Specifies the user context under   which the command should execute.

    /P   [password]Specifies the password for the given   user context. Prompts for input if   omitted.

    /RU  username  Specifies the "run as" user account   (user context) under which the task   runs. For the system account, valid   values are "", "NT AUTHORITY\SYSTEM"   or "SYSTEM".

    /RP  [password]Specifies the password for the   "run as" user. To prompt for the   password, the value must be either   "*" or none. This password is   ignored for the system account.

    /SC  schedule  Specifies the schedule frequency.   Valid schedule types: MINUTE, HOURLY,   DAILY, WEEKLY, MONTHLY, ONCE,   ONSTART, ONLOGON, ONIDLE.

    /MO  modifier  Refines the schedule type to allow    finer control over schedule   recurrence. Valid values are listed    in the "Modifiers" section below.

    /D   days      Specifies the day of the week to run   the task. Valid values: MON, TUE,   WED, THU, FRI, SAT, SUN and for   MONTHLY schedules 1 – 31 (days of the   month). Wildcard "*" specifies all   days.

    /M   months    Specifies month(s) of the year.   Defaults to the first day of the   month. Valid values: JAN, FEB, MAR,   APR, MAY, JUN, JUL, AUG, SEP, OCT,   NOV, DEC. Wildcard "*" specifies   all months.

    /I   idletime  Specifies the amount of idle time to    wait before running a scheduled    ONIDLE task.   Valid range: 1 – 999 minutes.

    /TN  taskname  Specifies a name which uniquely   identifies this scheduled task.

    /TR  taskrun   Specifies the path and file name of   the program to be run at the   scheduled time.   Example: C:\windows\system32\calc.exe

    /ST  starttime Specifies the start time to run the    task. The time format is HH:mm (24    hour time) for example, 14:30 for    2:30 PM. Defaults to current time.

    /RI  interval  Specifies the repetition interval in   minutes. This is not applicable for   schedule types: MINUTE, HOURLY,   ONSTART, ONLOGON, ONIDLE.   Valid range: 1 – 599940 minutes.   If either /ET or /DU is specified,   then it defaults to 10 minutes.

    /ET  endtime   Specifies the end time to run the   task. The time format is HH:mm    (24 hour time) for example, 14:50   for 2:50 PM. This is not applicable   for schedule types: ONSTART, ONLOGON,   ONIDLE.

    /DU  duration  Specifies the duration to run the   task. The time format is HHHH:mm.   This is not applicable with /ET and   for schedule types: ONSTART, ONLOGON,   ONIDLE. If /RI is specified, then it   defaults to 1 hour.

    /K     Terminates the task at the endtime or   duration time. This is not applicable   for schedule types: ONSTART, ONLOGON,   ONIDLE. Either /ET or /DU must be   specified.

    /SD  startdate Specifies the first date on which the   task runs. The format is mm/dd/yyyy.   Defaults to the current date. This is   not applicable for schedule types:   ONCE, ONSTART, ONLOGON, ONIDLE.

    /ED  enddate   Specifies the last date when the task   should run. The format is mm/dd/yyyy.   This is not applicable for schedule   types: ONCE, ONSTART, ONLOGON, ONIDLE.

    /IT    Enables the task to run interactively   only if the /RU user is currently   logged on at the time the job runs.   This task runs only if the user is   logged in.

    /Z     Deletes the task if it is not   scheduled to run again.

    /F     Forcefully creates the task and   suppresses warnings if the specified   task already exists.

    /?     Displays this help message.

Modifiers: Valid values for the /MO switch per schedule type:
    MINUTE:  1 – 1439 minutes.
    HOURLY:  1 – 23 hours.
    DAILY:   1 – 365 days.
    WEEKLY:  weeks 1 – 52.
    ONCE:    No modifiers.
    ONSTART: No modifiers.
    ONLOGON: No modifiers.
    ONIDLE:  No modifiers.
    MONTHLY: 1 – 12, or
    FIRST, SECOND, THIRD, FOURTH, LAST, LASTDAY.

Examples:
    ==> Creates a scheduled task "doc" on the remote machine "ABC"which runs notepad.exe every hour under user "runasuser".

SCHTASKS /Create /S ABC /U user /P password /RU runasuser /RP runaspassword /SC HOURLY /TN doc /TR notepad

    ==> Creates a scheduled task "accountant" on the remote machine "ABC" to run calc.exe every five minutes from the specifiedstart time to end time between the start date and end date.

SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE /MO 5 /TN accountant /TR calc.exe /ST 12:00 /ET 14:00 /SD 10/20/2002 /ED 10/20/2002 /RU runasuser /RP

    ==> Creates a scheduled task "gametime" to run freecell on the first Sunday of every month.

SCHTASKS /Create /SC MONTHLY /MO first /D SUN /TN gametime  /TR c:\windows\system32\freecell

    ==> Creates a scheduled task "report" on remote machine "ABC"to run notepad.exe every week.

SCHTASKS /Create /S ABC /U user /P password /RU runasuser /RP runaspassword /SC WEEKLY /TN report /TR notepad.exe

    ==> Creates a scheduled task "logtracker" on remote machine "ABC"to run notepad.exe every five minutes starting from thespecified start time with no end time. The /RP password will beprompted for.

SCHTASKS /Create /S ABC /U domain\user /P password /SC MINUTE /MO 5 /TN logtracker  /TR c:\windows\system32\notepad.exe /ST 18:30 /RU runasuser /RP

    ==> Creates a scheduled task "gaming" to run freecell.exe startingat 12:00 and automatically terminating at 14:00 hours every day

SCHTASKS /Create /SC HOURLY /TN gaming /TR c:\freecell /ST 12:00 /ET 14:00 /K

Advertisements
 
Leave a comment

Posted by on September 25, 2009 in Cmdlets&Tools

 

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: