How to run Windows batch files silently in the background

There are times when we want to run a batch file, program or command from the Windows command prompt but we don’t want the command prompt window to appear or to hang around on the desktop. For example, I have a batch script which backs up a load of files and it is triggered by the Task Scheduler every day, I don’t want a command prompt window suddenly appearing and staying open on the desktop every time this backup starts. e.g. I’m watching a movie on my HTPC and a window pops up and interrupts.

command prompt batch file

There is a fairly simple way to do it using a vbs script…

Set the scheduled task to run your command line from a batch file but using wscript as follows:

As an example, using notepad create a .bat file called date.bat  with this line:

Save date.bat wherever you want. Double click it and it will open a command prompt window briefly, run the command and close the window again. You will now have a new file in the same location as date.bat called data.txt with today’s date in it.

Ok, this is a very short and simple command but you can imagine that if you have a command which takes a while to run and has a lot of on-screen output then the command prompt window may get in the way. So how do we get rid of it and still let the program run?

Create a new file in notepad with the following content:

Now save it as Launcher.vbs

If you want the command prompt window to be visible but minimised you can change the ‘0’ in line 26 above to a ‘7’:

 

You can now run your date.bat file silent in one of two ways…

  1. Through Task Scheduler
    task scheduler batch files silent
    Create a new task to run at your appointed date/time with the following action:

     
  2. Create Another .bat File
    It may seem counter intuitive to create another .bat file to run the first one but this second one will open a command prompt window very quickly, call the vbs script then close the command prompt window while the vbs script runs the first file in the background.So while you do end up with another command prompt popping up then disappearing, you don’t get a window open for the duration of your first task.

    This is my preferred way of doing it when, for example, I have to run a startup program which runs my LED Ambilights. The Ambilight program runs in a command window and if I didn’t use this trick then the command prompt running the lights would stay open the whole time my computer was on. This way there is no persistent annoying window.

    So create another .bat file and call it whatever you want. Then populate it with the same command as you would have used for the Task Scheduler action:

 

Obviously you can use the same ‘Launcher.bat’ file to run any other .bat files just by amending the .bat file you call in your scheduled task or other.bat file.

 


 

Note that I did find this info on the internet some time ago but I can’t remember where or I would have given credit! If it was you let me know in the comments.

Leave a Reply

(email optional)