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

16 Comments

  1. Flow
    said this on Monday, August 8th 2011 1:05 pm

    Lovely, that made my day :)

  2. Victor, from Rio de Janeiro
    said this on Thursday, June 9th 2011 10:51 pm

    Great trick, thanks a lot!

  3. jay somerset
    said this on Friday, April 1st 2011 10:54 pm

    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.

  4. kanenas
    said this on Sunday, February 6th 2011 11:45 pm

    is there a way to make the script run our .bat file as administrator?

  5. MadQueen
    said this on Friday, December 31st 2010 5:34 pm

    working perfect . Tnk s

  6. said this on Monday, September 27th 2010 2:57 am

    Wow another gr8 script thanks

  7. mr.Rome
    said this on Wednesday, September 22nd 2010 9:09 pm

    Like the script, Thanks a bunch

  8. said this on Sunday, August 29th 2010 5:40 am

    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.

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

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

Leave a Reply