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/.CMD file execution is complete. 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. Both options are discussed below.

Running .BAT or .CMD files in minimized mode

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 in invisible mode

Windows Script Host’s Run Method allows you run a program or script in invisible mode.

Sample Code

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Batch Files\syncfiles.bat" & Chr(34), 0
Set WshShell = Nothing

Copy the lines above to Notepad and save the file with .VBS extension. Edit the .BAT file name and path accordingly, and save the file. Double-click the .VBS file to run it.

(Ref: Run Method. Setting intWindowStyle parameter to 0 hides the window)

Related Posts


Email SubscriptionPrefer an E-mail subscription?

Enter your email address:

Delivered by FeedBurner

26 Comments

  1. Pane in the Glass
    said this on Sunday, March 1st 2009 3:47 am

    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!

  2. Keith Leitch
    said this on Wednesday, January 28th 2009 1:23 am

    What a good tip! Can you provide any syntax that will also pass through commandline parameters?

  3. Kirill
    said this on Wednesday, December 3rd 2008 5:23 pm

    Man, this is just great. Thank you so much.

  4. Mike
    said this on Wednesday, November 19th 2008 11:25 am

    Thank you so much, I been trying to automate (and schedule) disk defragger and with this script and a ( defrag C: -f ) batch file I can be online and defrag my disk drive with out any annoying UI windows popping up :)

    Thank you!!

  5. said this on Friday, October 10th 2008 8:29 pm

    @Alva: It works fine here. I used the wait.exe tool from (http://www.wcscnet.com/FTP/Freeware/Wait100.zip). Waits correctly for the specified time (in seconds) and carries out the batch command.

  6. Alva
    said this on Friday, October 10th 2008 7:56 pm

    I’ve tried the second option (run batch file by running .vbs file)
    works fine, but in my originally bat file i call an exe file which slows the process(wait.exe, this file works as a clock so u can delay actions in seconds).
    It seems that the vbs script doesn’t consider this file!

    need a little help!!

  7. ju.c
    said this on Thursday, August 14th 2008 4:05 pm

    I like this the best:
    Hidden Start – run apps in the background
    http://www.ntwind.com/software/utilities/hstart.html

  8. said this on Sunday, August 10th 2008 8:32 am

    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…

  9. said this on Tuesday, August 5th 2008 3:58 pm

    Thanks for the tip! Even on Vista I find uses for batch files (such as manually refreshing my network connection).

  10. said this on Tuesday, August 5th 2008 1:27 pm

    Wow, thanks! I always have two command prompts everythime I launch this machine to make my virtual hard drives (SUBST) working. (One for admin level, other standard level). I’m not seeing them all the time, cause the tast scheduler makes it fast already, but when it does, it looks like my system is doing crazy stuff for others. Now I can hide it totally because of this script!

    Many thanks!

Leave a Reply