Friday, October 21, 2011

Run minimized batch file in Task Scheduler

I have a batch file scheduled in Windows Task Scheduler. The problem is it will always popup a window when running. Yes I want to see the window but I want it minimized instead of blocking my current view. Should an error occurs the batch file will pause and I will attend to it.

Some suggested using third-party program to minimize the window. Some suggested using Windows Script.

The solution is simple, use this: cmd /c start "title" /min "batch file"
For example: cmd /c start "Backup" /min "d:\my documents\scripts\backup.bat"

Be cautious that the start command will treat the first double-quoted string as title. So if you do this: 
  • cmd /c start /min "d:\my documents\scripts\backup.bat" 
you will just get a command prompt window entitled "d:\my documents\scripts\backup.bat" without the batch file running. Thus it's a good idea to always put a title to prevent scratching your head later.

There is one problem though, that you have to put an exit at the end of your batch file. Otherwise the batch file window will stay there when it is finished.

This is how you convert the above command into the Action of a scheduled task:
  1. Put "cmd" in Program/script.
  2. Put the rest in Add arguments (optional), eg: /c start "Hello" /min "d:\my documents\scripts\backup.bat"


  1. Thanks a lot! This saed my life dude!

  2. This comment has been removed by a blog administrator.

  3. Very useful, remarkably the part where you "translate" it into a scheduled task!
    The one point I'd like to add here is related to the end of the script: if the script does not have an "exit" within it, then a terminal screen will be left opened after the task is done, to avoid such behavior, just add " ^& exit" (without quotes) in the end of the command line, so it would be something like:

    /c start "Hello" /min "d:\my documents\scripts\backup.bat" ^& exit

    Hope it helps as much as the original topic did for me.
    Thank you and cheers!

  4. there is some problem:
    each execution its open a new shell because the "start" command and left it opened and not closed.