Calling vbscript from another vbscript file passing arguments

vbscript

I am using the below script to call another script .The issue is I have to pass the arguments which I retrieve by WScript.Arguments to the second script that I am calling .can someone please tell me how to do that.

Dim objShell
Set objShell = Wscript.CreateObject("WScript.Shell")

objShell.Run "TestScript.vbs"    

Set objShell = Nothing

Best Answer

You need to build your argument list with proper quoting of the arguments. You also need to differentiate between named and unnamed arguments. At the very minimum, all arguments with spaces in them must be put between double quotes. It doesn't hurt, though, to simply quote all arguments, so you could do something like this:

Function qq(str)
  qq = Chr(34) & str & Chr(34)
End Function

arglist = ""
With WScript.Arguments
  For Each arg In .Named
    arglist = arglist & " /" & arg & ":" & qq(.Named(arg))
  Next
  For Each arg In .Unnamed
    arglist = arglist & " " & qq(arg)
  Next
End With

CreateObject("WScript.Shell").Run "TestScript.vbs " & Trim(arglist), 0, True
Related Topic