zoombody

by Dan Rice

 

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.


This article has a comments feed and a trackback.
 

Comments // there are 9 comments

Robby says:

Doesn’t work for me I still see a flash of cmd witch i won’t see if you create a shortcut and select run :minimized in Win7

Dan says:

Guest, the point of this script is that it is self-contained. A second launcher script works but is less elegant.

Robby, you are correct that a shortcut does a cleaner job of minimizing the window, but this is for situations where a shortcut doesn’t do the trick (e.g. Task Scheduler) or, again, where you want things to be self-contained.


 

Leave a comment