Count Then
CommandLine = Arguments(Number - 1)
Else
CommandLine = ""
End If
End Function
For example, to display the second command-line parameter passed to a
script, issue the following statement:
MsgBox CommandLine(2)
Object References | 535
Scripting and
Automation
Although the command line may seem to be an antiquated concept, it??™s still
very much a part of Windows. When you double-click on a .vbs file, for
example, Windows actually executes the following command:
wscript.exe filename.vbs
where filename.vbs (the file that was double-clicked) is the command-line
parameter for wscript.exe, telling it which script to run. (See ???File Type Associations,???
in Chapter 3, for the nitty-gritty.) Scripts also accept command-line
parameters, which are entered like this:
wscript.exe filename.vbs param1 param2
The two additional parameters (you can have as many as you like), param1
and param2, are both passed to the script as command-line parameters, and
can be retrieved during runtime by referencing CommandLine(1) and
CommandLine(2), respectively.
One of the most common uses of command-line parameters in scripts is to
accept filenames, and there are two circumstances when this is most useful:
??? Drag one or more items onto the script file icon. Note that this didn??™t
work in some earlier versions of Windows, as scripts were considered to
be documents instead of programs.
??? Place the script in your Send To folder. Then, right-click one or more
items in Explorer, select Send To, and then select the name of the script.
Pages:
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744