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 .c
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
Use:
objShell.Run "TestScript.vbs arg1 arg2"
If one of the arguments contains spaces then you will need to embed these in quotes, probably like this:
objShell.Run "TestScript.vbs arg1 arg2 ""this is three"""
or it may accept apostrophes (I haven't tried this recently).
I found the answers a little confusing, so here is mine, which in my mind shows it more simply. The other answer aren't wrong, just different (slightly).
in test.vbs file:
Set shell = CreateObject("WScript.Shell")
shell.CurrentDirectory = "C:\some\path\"
x = "testing"
shell.Run "test1.vbs " & x
in C:\some\path\test1.vbs
file:
x = WScript.Arguments.Item(0)
msgbox x
resulting message box from test.vbs file, passed to test1.vbs file:
testing