How can I pass and access command line arguments in VBscript?
Asked
Active
Viewed 1.5e+01k times
2 Answers
92
Set args = Wscript.Arguments
For Each arg In args
Wscript.Echo arg
Next
From a command prompt, run the script like this:
CSCRIPT MyScript.vbs 1 2 A B "Arg with spaces"
Will give results like this:
1
2
A
B
Arg with spaces

aphoria
- 19,796
- 7
- 64
- 73
-
21You can access it directly with `WScript.Arguments.Item(0)`. Item 0 is not the command's name (as it is in other languages); in Aphoria's example above it would be the string "1". – Alexander Bird Aug 06 '13 at 19:24
61
If you need direct access:
WScript.Arguments.Item(0)
WScript.Arguments.Item(1)
...

Jerther
- 5,558
- 8
- 40
- 59
-
4You can also drag and drop a file onto a script in Explorer, which will run the script with the first argument set to the file path and name. – Simon Sellick Apr 16 '16 at 13:07
-
7