Schtasks with multiple actions

command linewindows task scheduler

I am trying to create a schedule task using command line which has multiple actions running more than one batch files in sequence among other things

SCHTASKS /Create /TN TaskName /SC ONLOGON 
/TR C:\ost\sanAuto.bat
/TR C:\ost\ClEvtLog.cmd

What I have tried that didn't work:

SCHTASKS /Create /TN tsk /SC ONLOGON /TR "C:\sanAuto.bat","C:\ClEvtLog.cmd"

this one create single action to run a program as "C:\sanAuto.bat","C:\ClEvtLog.cmd"

SCHTASKS /Create /TN tsk /SC ONLOGON /TR "C:\sanAuto.bat" /TN "C:\ClEvtLog.cmd"

This one says multiple /TN not allowed

Is there a way to create tasks from command line and specify multiple actions?

Note 1
Exporting and importing the xml is not something i want to do
http://iislogs.com/steveschofield/2009/03/20/creating-a-scheduled-task-with-multiple-actions-using-command-line-in-windows-server-2008/

Best Answer

  • SchTasks does not allow you to define multiple Actions using the TR switch. To define multiple Actions, you need to define your task in an XML file, and then use the XML switch to import the settings.

    From schtasks /create /?:

    /XML  xmlfile      Creates a task from the task XML specified in a file.
                       Can be combined with /RU and /RP switches, or with /RP
                       alone, when task XML already contains the principal.
    

    The easiest way to define the task in XML is to use Windows' Task Scheduler GUI to create your task (with multiple Actions defined) and then "Export" it to XML.

    Task Scheduler GUI