VBScript – Passing Named Arguments

I am always forgetting this so I have posted it so I can refer back to this when needed.  Sometimes via a command line you want to be able to pass command line parameters to a vbscript. e.g.

cscript.exe myscript.vbs /Parameter:value

The vbscript to handle this is as follow:

Option Explicit
Dim colNamedArguments

Set colNamedArguments = Wscript.Arguments.Named
If colNamedArguments.Exists("Parameter") Then
    Wscript.echo "Parameter Exists!"
    Wscript.echo "Parameter = " & _
         colNamedArguments.Item("Parameter")
End If

For more information see the following microsoft article :  http://technet.microsoft.com/en-us/library/ee156618.aspx

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.