Take the 2-minute tour ×

I have a batch file, this batch file will not start automatically, it will only run when i double click on it.
Can I run the batch file in the background when I double click on it.

share|improve this question

3 Answers 3

Well, you can start it minimized with start, if that is enough. Really hiding it is difficult (although I can think of an option right now).

Basically you need to determine whether the batch has been started by double-clicking it. You can do this by defining a special variable and look for it:

@echo off
if not defined FOO (
  set FOO=1
  start /min "" %~0
  exit /b

rem here whatever you wanted to do originally in the batch

As long as the FOO variable isn't defined (which is probably the default almost everywhere), this batch will launch itself minimized again, but with the variable defined first. Environments are passed to subprocesses, which is why this works.

share|improve this answer
This is my favorite method. I love this snippet. –  djangofan Nov 2 '11 at 19:03

you would generally need something else to run the script in that manor i.e. Create a shortcut, and set the “Run” field for the shortcut to “Minimized’.

share|improve this answer

Once you click or tab away from the cmd.exe window that the batch file is running it, it's "in the background" -- I'm not really sure what you want but it sounds like you might be asking how to run the batch file without displaying the cmd.exe window.

If so I can think of two ways: first, you can create a shortcut to the batch file, right click it, and in the properties there set the shortcut to run minimized (should be a drop down option next to Run).

You can also wrap invocation of the batch file in a VBScript file using Windows Script Host's shell object (calling the Run method) to run the batch file invisibly. Passing 0 as the intWindowStyle parameter will suppress display of a window or anything.

share|improve this answer

Your Answer


