Skip navigation

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

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 If
End If
If WScript.Arguments.Unnamed.Count > 0 Then
    WScript.Echo "First unnamed argument:" & WScript.Arguments.Unnamed(0)
End If


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish