Collection Property:  WScript.Arguments

WScript.Arguments

The Arguments property is read only and returns the collection of arguments supplied when invoking the current script. This collection is actually an object of type WshArguments. The argument list does not include the name of the host executable file (cscript or wscript), or the name of the script being invoked.

The following VBScript code illustrates the use of this property when used in a script that is invoked with the command line "cscript test.vbs hello world".

Code:
Set objArgs = WScript.Arguments
WScript.Echo WScript.Arguments.Count
For Each strArg in objArgs
    WScript.Echo strArg
Next


Output:
2
hello
world


The corresponding JScript code would be as follows, since JScript 5.1 cannot iterate collections using the "for each ... in" syntax.

Code:
objArgs = WScript.Arguments
WScript.Echo(WScript.Arguments.Count());
for (i=0; i<objArgs.length; i++)
{
    WScript.Echo(objArgs(i))
}


Output:
2
hello
world

Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information