4
1
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/
1FYI:
TR
is not "TRigger", it's "Task (to) Run" (a Trigger is what starts the task, which isSC
("Schedule") from the command-line).TN
= Task Name, each task can only have one name (your third example). – Ƭᴇcʜιᴇ007 – 2016-05-04T16:36:21.983Ahh 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). – Ƭᴇcʜιᴇ007 – 2016-05-04T16:45:08.590
Why not just make a script that runs those two other batch script files, and then run that single script with your task? – Ƭᴇcʜιᴇ007 – 2016-05-04T16:47:15.040
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 – 2016-05-04T16:48:34.300
Don't forget about
– Ƭᴇcʜιᴇ007 – 2016-05-04T16:51:03.713start
and/orcall
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).i did not use start or call if i use start to call a batch do i need to use exit in the called batch? – SeanClt – 2016-05-04T16:53:54.483
Shouldn't have to, but an extra "exit" at the end of a batch usually doesn't hurt.. ;) – Ƭᴇcʜιᴇ007 – 2016-05-04T16:55:02.250