WSH Command Line Arguments

Information related to the use of iMacros for uptime monitoring, performance and regression testing of websites.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team
Post Reply
User avatar
Tech Support
Posts: 4948
Joined: Tue Sep 20, 2005 7:25 pm
Contact:

WSH Command Line Arguments

Post by Tech Support » Mon Jan 16, 2006 3:06 pm

A Windows Script Host (WSH) script can use command line arguments. These can be useful when you wish to pass some information into a script. The test.vbs example below is used at the command line by entering something like either of the following:

cscript test.vbs a b c
wscript test.vbs a b c

There are very few differences between cscript and wscript. Cscript is a console-based application and runs inside an MS-DOS box. The first command uses cscript to run test.vbs with a, b, and c as the command line parameters (arguments). The second command uses wscript to run test.vbs and has a, b, c as the command line parameters.

To get the command line parameters inside the VBS file please use:

Code: Select all

set args = WScript.Arguments
num = args.Count

if num = 0 then
   WScript.Echo "No command line parameters!"
   WScript.Quit 1
end if

for k = 0 to num - 1
   msgbox args.Item(k)
next
WScript.Arguments is the collection containing the information on the arguments. Like all collections it has a Count property and an Item property, both of which are used above. Note how the Count is checked to see if it is zero. If so, we display an error message and quit the program. Item is an array of strings, and Item(k) gives a string containing the value supplied by the user as argument k.
Post Reply