VBScript Tutorials - Herong's Tutorial Examples - v6.03, by Herong Yang
Running VBScript Code Files
This section provides a tutorial example on how to run a VBScript file with or without 'cscript/wscript' command.
Now let's write and run our first VBScript with WSH.
Create a VBScript example file, Hello_Echo.vbs, with the following statements:
' Hello_Echo.vbs '- Copyright (c) 1998 HerongYang.com. All Rights Reserved. Set oArgs = WScript.Arguments If oArgs.Length = 0 Then WScript.Echo "Hello world!" For Each sArg In oArgs WScript.Echo "Hello " & sArg Next
Run Hello_Echo.vbs in many ways in a command window:
C:\herong>cscript Hello_Echo.vbs Herong Tom Hello Herong Hello Tom C:\herong>wscript Hello_Echo.vbs Herong Tom (Dialog box showing "Hello Herong") (Dialog box showing "Hello Tom") C:\herong>cscript //h:cscript The default script host is now set to "cscript.exe". C:\herong>Hello_Echo.vbs Herong Tom Hello Herong Hello Tom C:\herong>cscript //h:wscript The default script host is now set to "wscript.exe". C:\herong>Hello_Echo.vbs Herong Tom (Dialog box showing "Hello Herong") (Dialog box showing "Hello Tom")
Noticed that Hello_Echo.vbs can be executed in 3 ways:
Table of Contents
Introduction of VBScript - Visual Basic Scripting Edition
Variant Data Type, Subtypes, and Literals
Numeric Comparison Operations and Logical Operations
String Operations - Concatenation and Comparison
Variable Declaration and Assignment Statement
Expression and Order of Operation Precedence
Statement Syntax and Statement Types
Array Data Type and Related Statements
Array References and Array Assignment Statements
Conditional Statements - "If ... Then" and "Select Case"
Loop Statements - "For", "While", and "Do"
"Function" and "Sub" Procedures
Inspecting Variables Received in Procedures
Error Handling Flag and the "Err" Object
Regular Expression Pattern Match and Replacement
scrrun.dll - Scripting Runtime DLL Library
IE Web Browser Supporting VBScript
IIS ASP Server Supporting VBScript
What is WSH (Windows Script Host)?
"cscript.exe/wscript.exe" Command Version and Options
"WScript" Runtime Object Hierarchy
"oShell.Exec(cmd)" - Running System Command with a Script