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
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.

  • I searched like this script. It works ..

  • Luis Carmo

    You’re the greatest !!! ๐Ÿ™‚ thanks

  • Patrick

    Hi Dan,

    This is a great script – simple, yet effective!

    Thanks, Patrick

  • guest

    (While old, people will find this thread in a search)
    Alternatively have one batch file which does all the work (worker.cmd, say), but invoke it with a batch file with the single command
    start /min worker.cmd

  • Robby

    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

  • Dragu

    Superb there. Nice done ๐Ÿ™‚

  • othman

    is this code work in windows 7 ?????

  • malte

    neat, thanks!

  • tito

    thanks, used it and adopted it ๐Ÿ™‚

  • Facundo

    Thanks thanks thanks!! !!!!!!!!!!!!!!!!!!!!!!

  • jippeenat

    Hey, thanks! This is super useful in the enterprise environment that I work in.

  • 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.

  • The point of this script is that it is self-contained. A second launcher script works but is less elegant.

  • Pingback: Windows 2008 SP2 - Disconnessione da RemoteApp application.()

  • dblue007


  • GastonMarzoratti

    This was just was I was looking for…Thanks
    I added %* ย to pass all the parameters
    start /min cmd /C “%~dpnx0” %*

  • carladesile

    haha I just knew there would be a simple solution out there somewhere – And then I stumble up on ย this! Awesome. Thank You

  • nazzymac

    This is perfect thanks

  • Brian Wade

    OH THANK YOU!!!!!!!! Been searching for this for hours!!!

  • Wow this is perfect, so simple to add at the start of the file.

  • Oh, yeah, nice solution! Helped a lot.

  • David Green

    Thanks so much. Worked with a start command after the :minimized tag, but did not work the the call command. Helpful to put a pause after the command to diagnose problems. Thanks again for the solution.

  • Thomas

    Dan, you’re hero for me – thank you very much! ๐Ÿ™‚

  • Gio Crux

    Thank you!! Been looking for this simple thing for hours :/

  • GordonRanger

    what a bunch of kludge (not your solution per se – just that windoze forces this because of M$ narrow mindset)

  • GordonRanger

    Try this for an exercise: run a scheduled task that does not open a dos window; I’m convinced it can’t be done without some more kludge of some kind. I’ve tried using powershell (with -nointeractive); schtasks with /ru; the taskscheduler GUI; creating a short cut with the command in the command box and setting it to run minimized. This is *so easy* in Linux, it absolutely boggles my mind that the folks at M$ have made this *so difficult*. What I may try next is writing a *service* to do this, imagine that, having to write a *service* to run a oneliner so it doesn’t open an effin dos window.

  • GordonRanger

    Ok, I found a solution that is not too hard (I empathize with non-computer-literates when I help them with their stuff when I encounter this stuff myself). Anyhoo, if I use the “Task Scheduler” and click on the button that says:

    “Run whether user is logged on or not”

    under the “General” tab then the dos box does not appear.

    It’ll prompt you for credentials, and will start failing (as I understand it) when you change your password, but still it is better than writing a service.

    Note the my task to run is specified in the “command” box in a shortcut which is pointed to in “Details” in the “Actions” tab. I don’t have the gumption to see what happens if I call a powershell script or a command (.cmd) file.

  • Nathan Griffiths

    Hi Dan, great bit of code ๐Ÿ™‚
    Only problem I’m having, it messes with a particular batch file that contains the single line of code “C:Program Files (x86)WinRARWinRAR.exe” x %1 “%~n1”.
    This is to automatically extract a RAR file to a folder with it’s name, when double-clicking the RAR (learnt here:
    When I add your code to the top of the file, WinRAR throws up an error that says “No archives found”. So I presume that the variable in my code is being mixed somehow with variable(s) in your code? Any thoughts on how to make the two work together?

  • James ElectroGeek Killick

    I had an app that used a version of python that was different to the version of python that I needed to run a script. If I put start /min in the python / cmd call from the old python, it would not work, but just call the bat file is fine, then I can use the batch file itself to minimise while it is calling the python in the other version. Worked for me…!

  • Thank you so much Dan, I have searched and searched for how to run a batch file from the task manager minimized with no luck.
    This works, thank you again…

  • konzen dojie

    not working