I'm executing the following command :

schtasks /create /tn "test" /ru system /SC onevent /TR "test" /F /RL HIGHEST /MO "*[System[Provider[@Name='SupportAssistService'] and EventID=900]]" /EC APPLICATION

[Using the command references for SCHTASKS for Server 2008 and server 2012, I'm unable to figure out how to do the following options that are available in the task scheduler GUI.

  1. Undo/Uncheck the power option which says start the task only when on AC power, as well as stop if computer switches to battery power
  2. Run task as soon as possible after a scheduled start is missed
  3. If the task fails, restart every x minutes up to y times
  4. If the task is already running then do not start a new instance

Does anyone know how to create a task from the command line with those options?


Solution 1:

Despite the schtasks has new command line options, they are still limited. You can however create a task with command line from a XML file containing all the settings.

You can create a task in Task Scheduler GUI and export is as a XML. This file can be used as a model for further tasks. Then, you can create a task on another computer with commandline:

schtasks /create /xml "ExportedTask.xml" /tn "Name of the New Task"

The settings of your questions are (in corresponding order):

  <Settings>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RestartOnFailure>
      <Interval>PT10M</Interval>
      <Count>3</Count>
    </RestartOnFailure>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
  </Settings>