How to run .BAT files invisibly, without displaying the Command Prompt window

Batch files (.BAT) and Windows NT Command Script (.CMD) files run in console window when double-clicked. This means that the Command Prompt window will be visible until the .BAT or .CMD file execution is complete.

run batch file hidden or invisible mode

To make .BAT or .CMD file execution less intrusive, you can configure it to run minimized. Or if the .BAT or .CMD file does not require user input during run time, you can launch it in invisible mode using a Script.

The built-in Task Scheduler in Windows is capable of launching programs in hidden mode. If you don’t want to proceed via the Task Scheduler route, check out the options discussed in this article.

Running .BAT or .CMD files in minimized mode

To run a batch file in a minimized window state, follow these steps:

  1. Create a shortcut to the .BAT or .CMD file. To do so, right click on the file, click Send To, Desktop (create shortcut)
  2. Right click on the shortcut and choose Properties
  3. In the Run: drop down, choose Minimized
  4. Click OK
  5. Double-click the shortcut to run the batch file in a minimized window state.

Running .BAT or .CMD files hidden (invisible mode) Using Script

Windows Script Host’s Run Method allows you run a program or script in invisible mode. Here is a sample Windows script code that launches a batch file named syncfiles.bat invisibly.

Reference: Run Method. Setting intWindowStyle parameter to 0 hides the window.

Let’s say we have a file named syncfiles.bat in C:\Batch Files directory. Let’s launch it in hidden mode using Windows Scripting.

  1. Copy the following lines to Notepad.
    Set WshShell = CreateObject("WScript.Shell") 
    WshShell.Run chr(34) & "C:\Batch Files\syncfiles.bat" & Chr(34), 0
    Set WshShell = Nothing

    Note: Replace the batch file name/path accordingly in the script according to your requirement.

  2. Save the file with .VBS extension, say launch_bat.vbs
  3. Edit the .BAT file name and path accordingly, and save the file.
  4. Double-click to run the launch_bat.vbs file, which in-turn launches the batch file syncfiles.bat invisibly.

RELATED: How to Automatically Elevate a Batch file to Run it as Administrator? -and- VBScripts and UAC elevation (Run as administrator)

Running .BAT or .CMD files hidden (invisible mode) Using NirCmd

NirCmd is a multipurpose command-line automation utility from the third-party vendor Nirsoft. We’ve covered NirCmd many times in the past on our site.

We can use NirCmd to run a program, script or batch file in hidden mode.



Download NirCmd and extract the file to your Windows directory.

From the Run dialog or Command Prompt, use the following syntax to launch a batch file or program in hidden mode:

nircmd exec hide [path to batch file]

Example:

nircmd exec hide "c:\batch files\syncfiles.bat"

run batch file hidden - nircmd exec

If you need to run the batch file elevated (as administrator), use the following command instead:

nircmd elevatecmd exec hide c:\batch files\syncfiles.bat

(NirCmd Command Reference – exec)

That’s it! If you know any other method to run a batch or CMD file in hidden mode, let us know.


One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support, my reader. It won't take more than 10 seconds of your time. The share buttons are right below. :)

About the author

Ramesh Srinivasan founded Winhelponline.com back in 2005. He is passionate about Microsoft technologies and he has been a Microsoft Most Valuable Professional (MVP) for 10 consecutive years from 2003 to 2012.

40 thoughts on “How to run .BAT files invisibly, without displaying the Command Prompt window”

  1. AutoHotkey can run things hidden too…
    Run, somebat.bat, , Hide
    …or…
    Run, %1%, , Hide

    …put the 2nd example in RunHidden.ahk…then add a Run Hidden option to the .bat right-click menu…

    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\batfile\Shell\RunHidden]
    @=”Run &Hidden”

    [HKEY_CLASSES_ROOT\batfile\Shell\RunHidden\Command]
    @=”\”C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\” \”C:\\Program Files\\AutoHotkey\\RunHidden.ahk\” \”%1\” %*”

    …I didn’t test that, but I hope you get the idea anyway…also I don’t know if this blog supports…
    [code]test[/code]
    …tags…so I didn’t use them…& no preview…

  2. You can use the Arguments property to pass command line parameters:

    WshShell.Run chr(34) & “C:\Batch Files\syncfiles.bat” & Chr(34) & WScript.Arguments(0), 0

    I found it useful to verify the command string before putting it into the script:

    WScript.Echo chr(34) & “C:\Batch Files\syncfiles.bat” & Chr(34) & WScript.Arguments(0)

    Hope that helps!

  3. Thank you! Worked great, I was using a .cmd script to run every 5 minutes and it was rather annoying that the command prompt window would pop up every 5 minutes to run it. The VBS you gave made it run completely invisible now. Thanks again.

  4. The minimizing the execution of the shortcut does not work in Windows 7 — shortcuts for .BAT files are not editable in the way described.

    The VBS approach works just fine, however.

    Thanks for that neat way of running a repetitive script inthe background.

  5. SWEET! Just what i was trying to do. I have batch jobs that run every minute and it’s annoying to have them pop up all the freakin time. Thanks so much!

  6. This is fantastic! Thank you very much!

    Next, to figure out how to pass the location and name of the .bat to be run, into the vbs script…then I could have 1 invisible.vbs script that executes the desired .bat file.

  7. Thanks for this, but I’m calling the bat file from an XML file that also includes parameters to be passed to it.
    How can I pass parameters to the bat file is I’m calling the VBS file instead?

  8. Marvellous! It is really helped us in WebLogic server to run in the background. it is almost equalent to Unix & and nohup.

  9. Useless explanation. What does “Copy the lines above to Notepad and save the file with .VBS extension.” mean???????

    What lines? I have a simple .bat file that I want to run “hidden”. This explanation looks really encouraging till I find an unexplainable statement like that.

    OK – I guess I’m just stupid.

  10. Awesome application!!! Would love the ability to copy and paste the GUID rather than have t export the .XML, rename that file and then do it again. Even better would be a data dump to a notepad or excel for rapid reference of the GUID.

  11. Wow! So this is what batch files are all about. This will really come in handy. I’ve already setup a MongoDB batch file to run invisibly and it is a delightful experience.

Leave a Comment