How to run a batch file without launching a "command window"? [duplicate]
Solution 1:
Save the following as wscript, for instance, hidecmd.vbs after replacing "testing.bat" with your batch file's name.
Set oShell = CreateObject ("Wscript.Shell")
Dim strArgs
strArgs = "cmd /c testing.bat"
oShell.Run strArgs, 0, false
The second parameter of oShell.Run
is intWindowStyle
value indicating the appearance of the program's window and zero value is for hidden window.
The reference is here http://msdn.microsoft.com/en-us/library/d5fk67ky.aspx
Solution 2:
This is just a simplification of Shaji's answer. You can run your batch script through a VBScript (.vbs) script like this:
HideBat.vbs
CreateObject("Wscript.Shell").Run "your_batch_file.bat", 0, True
This will execute your batch file with no command window shown.
Solution 3:
Just to expand on the "Use Windows Scripting" answers (which I consider best because it's built-in already) here's how to do it by using a single wrapper script and passing the name of the "real" batch file as a parameter. Additional parameters will be passed on to the batch file.
If WScript.Arguments.Count >= 1 Then
ReDim arr(WScript.Arguments.Count-1)
For i = 0 To WScript.Arguments.Count-1
Arg = WScript.Arguments(i)
If InStr(Arg, " ") > 0 Then Arg = """" & Arg & """"
arr(i) = Arg
Next
RunCmd = Join(arr)
CreateObject("Wscript.Shell").Run RunCmd, 0, True
End If
So e.g. save the above file as NoShell.vbs
somewhere then call:
NoShell.vbs c:\foo\my_batch_file.bat
Finally, if you're looking to run this from somewhere that doesn't understand the .vbs file (such as an "External Tools" in Visual Studio), you'll want to call C:\Windows\System32\wscript.exe
with the vbs file as its first parameter and your batch file as the second.
Solution 4:
Use start with the '/B' option. For example:
@echo off
start /B go.bat
Solution 5:
You can change the properties of the shortcut to run minimized.
To run it completely invisibly you'll need something else, like Windows Scripting.