Reputation: 16371
So I have a basic script that just prints out the parameters that are passed in:
projectName = ""
if Wscript.Arguments.Count > 0 then
projectName = Wscript.Arguments(0)
else
WScript.StdOut.WriteLine "No project specified"
end if
WScript.StdOut.WriteLine "Running script on project: " & projectName
When I run the script from the command line:
cit.vbs test
I get the message "No project file specified"
If I run it like this:
cscript vit.vbs test
I get the output: "Running script on project test"
Why is that?, why can't I pass a parameter in without specifying cscript at the start?
note I have configured my windows to run vbs files using cscript not wscript because I find wscript has weird issues and I don't want GUI elements - but that's a different question
Upvotes: 1
Views: 415
Reputation: 38755
What happens when you call a script without naming the interpreter/host, depends on the assoc/ftype file association settings.
So use
assoc .vbs
.vbs=VBSFile
and
ftype VBSFile
VBSFile=%SystemRoot%\System32\CScript.exe "%1" %*
to make sure that the command line pattern contains the %*
to forward the arguments.
Update wrt comment:
assoc/ftype are command line tools. A simple assoc /?
resp. ftype /?
will show you the details (including a sample that deals with parameters). But use the method you are familiar with.
Upvotes: 2