0

Currently, I am trying to trigger a second task to run when my first task (which runs a minimised batch file) ends. In the first task, I am running cmd.exewith the arguments /c start "" /min "C:\Custom Scripts\Test.bat" ^& exit. While this does launch the batch file minimised, as well as another cmd window which is open for a split-second, the arguments being immediately executed and then terminating means that the first task "completes" almost immediately after it opens, regardless of how long the batch file/second window continues to run for.

Conversely, if I change the arguments to /c start "" /min /wait "C:\Custom Scripts\Test.bat" ^& exit, then the first command window which launches the batch file will not close until the second minimised window does, and so the task does not complete/stop running until the batch file does. However, this also means that the first window is not minimised, which defeats the purpose of minimising the batch file.

Therefore, how can I run all opened/new windows minimised (or only open for a split-second), as well as making the scheduled task complete only when the batch file it's opening does?

ScottyN91
  • 51
  • 1
  • 6
  • It is unclear for me what you really want. The command `cmd.exe` starts a new command process. The command `start` with a batch file as process to execute starts one more separate command process which processes the batch file. The command `exit` terminates immediately the current command process which is the one started with `cmd.exe`. What about [How do I set a Windows scheduled task to run in the background?](http://stackoverflow.com/questions/6568736/) Run with any WWW search engine a search for __Windows scheduled task background__. – Mofi Sep 17 '16 at 18:20
  • To the close voters - this question has nothing to do with servers. Why are you voting to migrate to Server Fault? – DavidPostill Sep 17 '16 at 21:44
  • @Mofi Whilst the solution you linked to is useful for some other batch files I can think of, what I'm trying to achieve is to minimise both the first cmd.exe that is launched, as well as the second cmd.exe window which is what the batch file is running in. In addition, I also need to keep the first cmd.exe window open whilst the batch file is running so that the scheduled task does not complete until the batch file (and therefore the first cmd.exe window) does. Do you know if there is a utility similar to the one you mentioned which can minimise both windows rather than hide? – ScottyN91 Sep 18 '16 at 23:34
  • @Mofi Also, if I was able to run both windows minimised, then I could simply use the second set of arguments I posted (`/c start "" /min /wait "C:\Custom Scripts\Test.bat" ^& exit`) to keep the first window open until the second window with the batch script completes. This would therefore cause the task to complete only when the batch file does. Alternatively, if you can think of something that directly launches the batch script in a minimised state (without having to run the first cmd.exe window), which can also be run from task scheduler, I would be very appreciative. – ScottyN91 Sep 18 '16 at 23:38

0 Answers0