I am passing a batch script as the first argument to a VBScript, but when I call it to run, it does not run. It does nothing. No error, no nothing.
' calling VBScript from another VBScript file passing arguments
' https://stackoverflow.com/questions/17437633/
'
' Check if string contains space
' https://stackoverflow.com/questions/31370456/
Function EnquoteString(argument)
EnquoteString = Chr(34) & argument & Chr(34)
End Function
arglist = ""
With WScript.Arguments
For Each arg In.Unnamed
' Wscript.Echo "Unnamed: " & arg
If InStr(arg, " ") > 0 Then
' arg contains a space
arglist = arglist & " " & EnquoteString(arg)
Else
arglist = arglist & " " & arg
End If
Next
End With
' Wscript.Echo arglist
' Running command line silently with VBScript and getting output?
' https://stackoverflow.com/questions/5690134/
'
' Windows Script Host - Run Method (Windows Script Host)
' http://www.vbsedit.com/html/6f28899c-d653-4555-8a59-49640b0e32ea.asp
'
' Wscript.Echo Wscript.Arguments.Item(0)
' Run a batch file in a completely hidden way
' https://superuser.com/questions/62525/
CreateObject("Wscript.Shell").Run arglist, 0, False
This is how I call it within my batch file:
wscript .\silent_run.vbs ".\code.bat" "arg 1" "arg2" %*
This is how it is printed when I do echo:
As we may see, the arguments are received correctly. I think the problem is this line:
CreateObject("Wscript.Shell").Run arglist, 0, False
If I remove the ".\code.bat"
as argument and put it directly on the VBscript, it works correclty:
wscript .\silent_run.vbs "arg 1" "arg2" %*
...
CreateObject("Wscript.Shell").Run ".\code.bat " & arglist, 0, False
How can I receive the also the batch file, instead of hard code it into the VBScript?
Notice, I need to VBScript to be silent, i.e. no window showing up. Currently, it is already silent like this due: