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"




4 comments: