1
votes

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

1
There is no print command in VBScript. Your code errors.user6017774
@Noodles sorry I forgot to add the print function..will add itcode_fodder
@Noodles no GUI in that I don't need to do things like MsgBox (which is a graphical element you can call with wscript).code_fodder
@Noodles infact I just replaced the print function with part of what it does, because the other part is to log to a filecode_fodder
@Noodles also, I said GUI elements, not a GUI program, so no need to text-shout, thanks : )code_fodder

1 Answers

2
votes

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.