WSH Command Line Arguments

Information related to the use of iMacros for uptime monitoring, performance and regression testing of websites.

Moderator: iMacros Moderators

WSH Command Line Arguments

by Tech Support on Mon Jan 16, 2006 8:06 am

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)

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.
User avatar
Tech Support
Posts: 5003
Joined: Tue Sep 20, 2005 12:25 pm

Return to How-To's and Examples for Web Testing

Who is online

Users browsing this forum: No registered users and 1 guest

Website Monitoring