Q. How can my Vbscript extract named and unnamed arguments?

Jerold Schulman

November 21, 2006

1 Min Read
ITPro Today logo

You can extract named and unnamed arguments from the command line. If you have a /Name1: named argument, the following code can extract it, along with the first unnamed argument, if any:

WScript.Echo "There are a total of " & WScript.Arguments.Count & " arguments."WScript.Echo "There are " & WScript.Arguments.Named.Count & " named arguments."WScript.Echo "There are " & WScript.Arguments.Unnamed.Count & " unnamed arguments."If WScript.Arguments.Named.Count > 0 Then    if WScript.Arguments.Named("Name1")  "" Then       WScript.Echo "/Name1:" & WScript.Arguments.Named("Name1")    Else       WScript.Echo "No or nul ""/Name1:"" named argument was passed."    End IfEnd IfIf WScript.Arguments.Unnamed.Count > 0 Then    WScript.Echo "First unnamed argument:" & WScript.Arguments.Unnamed(0)End If


Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like