5

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/

7
  • 1
    FYI: TR is not "TRigger", it's "Task (to) Run" (a Trigger is what starts the task, which is SC ("Schedule") from the command-line). TN = Task Name, each task can only have one name (your third example). May 4, 2016 at 16:36
  • Ahh you added your edit while I was writing my answer. If you don't want to use XML importing, then you're pretty much out of luck, at least out of luck using SchTasks to create your task (you may be able to find a 3rd party alternative, personally I know of none). May 4, 2016 at 16:45
  • Why not just make a script that runs those two other batch script files, and then run that single script with your task? May 4, 2016 at 16:47
  • i did tried that a batch calling other batch but it just got stuck in the called batch and never went to my main batch, i think i should revisit my batch scripts
    – SeanClt
    May 4, 2016 at 16:48
  • Don't forget about start and/or call when calling batch files from batch files. Also, if you're using Windows 8/Server 2012+ you can also maybe look into using PowerShell to create your tasks. Not sure if it'll let you assign multiple actions or not (off-hand). May 4, 2016 at 16:51

1 Answer 1

8

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .