Run a Windows ("DOS") batch/cmd script minimized
Here’s a snippet of code I wrote that will force a Windows batch script to run in a minimized window. Insert it at the beginning of the script:
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
rem Anything after here will run in a minimized window
It works by having the script re-launch itself in a new minimized window. There are a few juicy batch scripting tricks in here that I recently picked up, like the %~dpnx0
syntax and the special :EOF
label. And the overall flag/callback syntax is generally useful for creating self-contained batch scripts.
Other start
switches besides /min
can provide different parameters for the child window, such as adjusting the CPU priority of the resulting process.