SCHTASKS

Create, delete, edit, list, start or stop a scheduled task. The task can be created on the local or a remote computer.

Syntax:

   Create a new scheduled task:
   SCHTASKS /Create [Connect_Options] Create_Options /TN taskname

   Delete the scheduled task(s)
   SCHTASKS /Delete [Connect_Options] /TN taskname [/F]
   
   Display all scheduled tasks:
   SCHTASKS /Query  [Connect_Options] [/FO format] [/NH] [/V]
   
   Run the scheduled task on demand:
   SCHTASKS /Run [Connect_Options] /TN taskname

   Stop the currently running scheduled task:
   SCHTASKS /End [Connect_Options] /TN taskname

   Change the properties of scheduled task:
   SCHTASKS /Change [Connect_Options] {[/RU username] [/RP password] [/TR taskrun]} /TN taskname

   Show the security identifier corresponding to a scheduled task name:
   SCHTASKS /ShowSID [Connect_Options] /TN taskname

 Connect_Options:
     /S system                      # Remote system (default is local)
    [/U username [/P password]]     # Submit job under this name

 Create_Options:
    /TR taskrun                     # Pathname of the executable to run
    /ST starttime                   # HH:MM (24 hour)
    [/RU username [/RP password]]   # Run job as this user
    /SC schedule [/MO modifier]     # When to run, see below
    [/D day]                        # Day = MON,TUE,WED,THU,FRI,SAT,SUN
    [/M months]                     # Month=JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC.
    [/I idletime]                   # 1 - 999 minutes (ONIDLE task only)
    [/SD startdate] [/ED enddate]   # Start and end date "dd/mm/yyyy"

 options:
    /TN   A name for the task
    /F    Force delete, ignore warnings even if the task is currently runnning.
    /FO   Output format: TABLE, LIST, CSV
    /NH   No header
    /V    Verbose output

    /SC schedule  The schedule frequency.
    Valid schedules: MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONCE, ONSTART,ONLOGON,ONIDLE.

    /MO modifiers allow finer control:

      MINUTE:  1 - 1439 minutes.
      HOURLY:  1 - 23 hours.
      DAILY:   1 - 365 days.
      WEEKLY:  1 - 52 weeks.
      ONCE:    No modifiers.
      ONSTART: No modifiers.
      ONLOGON: No modifiers.
      ONIDLE:  No modifiers.
      MONTHLY: 1 - 12, or FIRST, SECOND, THIRD, FOURTH, LAST, LASTDAY.

New options in Vista and above:

   /RI interval      # The Repetition Interval in minutes.

This is not applicable for the following schedule types: MINUTE, HOURLY, ONSTART, ONLOGON,
ONIDLE, and ONEVENT
. The valid range is 1 - 599940 minutes.
If either the/ET endtime or /DU duration parameters are specified, the default is 10 minutes.

   /ET endtime       # The End Time to run the task, format is HH:mm (24-hour time).

For example, 14:50 specifies 2:50PM.
This is not applicable for the following schedule types: ONSTART, ONLOGON, ONIDLE, and ONEVENT.

/DU duration      # A value that specifies the duration to run the task. 

The time format is HH:mm (24-hour time). For example, 14:50 specifies 2:50PM. This is not applicable with /ET endtime and for the following schedule types: ONSTART, ONLOGON, ONIDLE, and ONEVENT. For /V1 tasks (Task Scheduler 1.0 tasks), if /RI is specified, then the duration default is one hour. This option is available in Windows 2003 or greater (not XP).

/K      # A value that terminates the task at the end time or duration time. 

This is not applicable for the following schedule types: ONSTART, ONLOGON, ONIDLE, and ONEVENT.
Either /ET endtime or /DU duration must be specified.

/EC ChannelName   # A value that specifies the event channel for ONEVENT triggers.

/IT A value that enables the task to run interactively only if the /RU user is currently logged on at the time the task runs. The task runs only if the user is logged on.

/NP A value that indicates that no password is stored. The task does not run interactively as the given user. Only local resources are available.

/Z A value that marks the task to be deleted after its final run.

/XML xmlfile A value that creates a task from an XML file. This parameter can be combined with /RU and /RP switches, or with the /RP switch alone when the task XML already contains the principal.

/V1 A value that creates a task visible to Windows 2000, Windows Server 2003, and Windows XP platforms.

/F A value that forcefully creates the task and suppresses warnings if the specified task already exists.

/RL level A value that sets the run level for the task. Valid values are LIMITED and HIGHEST. The default is LIMITED.

/DELAY delaytime A value that specifies the wait time to delay the task after the trigger is fired. The time format is mmmm:ss. This option is only valid for schedule types ONSTART, ONLOGON, and ONEVENT.

Notes

For MONTHLY schedules give the DAY as a number 1 - 31 (default=1)

To prompt for the password, specify /RP * or /RP none

The User Account under which the Schedule service runs may require specific file access permissions, user permissions and drive mappings.

If the /RU username and /RP Password parameters match the currently logged-in user, the task will run interactively (visible in the foreground).

For the system account, /RU username can be written as "", "NT AUTHORITY\SYSTEM" or "SYSTEM", a Password is not required. The system account has full access to the local machine but has no permissions on any other machines (or mapped drives) across the Network.

The new task must be set to start a minimum of 1 minute into the future. The /SC option is a little inconsistent, under Windows XP it requires an HH:MM:SS value, under Vista and greater it will accept HH:MM but in all cases the SS value in seconds will be ignored and rounded down.

Power Saving

The property for "Wake up the machine to run this task" cannot be set using schtasks, but this property is essential if you need the task to run on a machine that has PowerSaving enabled.
To work around this, create a task on one computer using the control panel GUI. This will create a .job file in %windir%\Tasks\

To replicate the scheduled task onto other machines copy the .JOB file to %windir%\Tasks on each machine.

This techique will not retain any system account credentials, so if you need to run the tasks under System, run the following after copying the .JOB file:
SCHTASKS /CHANGE /RU "NT Authority\System" /TN "Yourtaskname"

UAC (User Account Control) prompts.

If a scheduled task invokes a UAC prompt, then the task may fail to run unattended. To prevent this issue (without disabling UAC completely) setup a 'Fix' using the Application Compatibility Toolkit.

Other languages.

If you are running a non-english language version of Windows then the Days and Months accepted by SCHTASKS may be localised.
e.g. Italian days: lun, mar, mer, gio, ven, sab, dom Italian months: gen, feb, mar, apr, mag, giu, lug, set, ott, nov, dic.

Examples:

Create a task to run at 11 pm every weekday

SCHTASKS /Create /SC weekly /D MON,TUE,WED,THU,FRI /TN MyDailyBackup /ST 23:00 /TR c:\backup.cmd /RU MyDomain\MyLogin /RP MyPassword

Now delete the task:

SCHTASKS /Delete /TN "MyDailyBackup" /f

Create a one-off task to run a script at exactly12 midday:

SCHTASKS /create /tn "once only" /tr "\"c:\my folder\one.cmd\" arguments" /sc ONCE /sd 12/29/2014 /st 12:00

Create a daily task to run a script at 5 pm:

SCHTASKS /create /tn "My Script" /tr "\"c:\my folder\script.cmd\" arguments" /sc daily /sd 12/29/2014 /st 17:00

Task Scheduler options are stored in the registry

HKLM\SOFTWARE\Microsoft\SchedulingAgent\

“We don’t wake up for less than $10,000 a day” ~ Linda Evangelista

Related:

Q823093 - Scheduled task does not run when the Path contains a space
WAITFOR - Wait for or send a signal.
Powershell: To schedule a PS task call Powershell.exe
Equivalent bash command (linux): crontab - Schedule a command to run at a later time


© Copyright SS64.com 1999-2014
Some rights reserved