VBScript Basics, Part 39 | Command Prompt (Arguments)


VBScripting (.vbs) Basic Tutorial On How-To:
Use arguments in vbscript by passing values through the command prompt. You can create each argument in the command prompt (cmd.exe) and then use them in your script.

Code Examples:
______________________________________________________

Option Explicit
Dim args, arg, list

Set args = WScript.Arguments

If Not args.Count = 3 Then
MsgBox “Not enough arguments. You need 3, and you have: ” & args.Count ,vbCritical
WScript.Quit
Else
For Each arg In args
list = list & arg & vbLf
Next
MsgBox list
End If
______________________________________________________
Option Explicit
Dim fname, lname, age

fname = WScript.Arguments(0)
lname = WScript.Arguments(1)
age = WScript.Arguments(2)

MsgBox age
______________________________________________________
Option Explicit
Dim fso, drives, drive

Set fso = CreateObject(“Scripting.FileSystemObject”)
Set drives = Wscript.Arguments

For Each drive In drives
msgbox fso.GetFolder(drive &”:”).Subfolders.Count ,vbOKOnly,”Folders in ” &drive
Next
______________________________________________________