How to run a batch file minimized

p2013 picture p2013 · Jul 7, 2013 · Viewed 32.6k times · Source

I want to run a batch file in minimized mode by another batch or vbs script. What i tried is:
batch1.bat

@echo off  
start /min batch2.bat

batch2.bat

@echo off  
{my program}  
del /f /q batch1.bat >nul  
del /f /q batch2.bat >nul  

When I try this everything works perfectly the second batch runs and does it's job but at the end a minimized command prompt window stays which says the windows can not fond the batch file and a simple prompt to the path of the batch file as like command prompt shows.

If i use exit command instead of this line del /f /q batch2.bat >nul from the second batch only then it works as i wish but it is important for my program to delete batch2 after it runs.
My only target is to run batch2 in minimized mode.so is there any help?i also cannot use shortcut to batch here.

Answer

Baodad picture Baodad · Dec 28, 2013

From this page:

cmd.exe /c start /min YourBatchFile.bat ^& exit

When running the command from the Task Scheduler, I had to execute cmd.exe as the program and put the rest in as arguments. Also, ^& exit did not close the resulting window for me when run from Windows 8's Task Scheduler. I had to build the exit command into my batch file for it to remove the window from the task bar when it was finished.