VBScript Tutorials - Herong's Tutorial Examples - Version 5.20, by Dr. 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) 2015, HerongYang.com, All Rights Reserved.

   Set oArgs = WScript.Arguments
   If oArgs.Length = 0 Then WScript.Echo "Hello wolrd!"
   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:

  • "cscript Hello_Echo.vbs ..." - Using host cscript.exe to execute.
  • "wscript Hello_Echo.vbs ..." - Using host wscript.exe to execute.
  • "Hello_Echo.vbs ..." - Using the default host, cscript.exe or wscript.exe. You can change the default host using the "cschipt //h:..." command.

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 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

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

WSH (Windows Script Host)

 What is WSH (Windows Script Host)?

 "csript.exe/wscript.exe" Command Version and Options

Running VBScript Code Files

 "WScript" Runtime Object Hierarchy

 "oShell.Exec(cmd)" - Running System Command with a Script

 WSF - Windows Script File XML Format

 References

 Printable Copy - PDF Version

Running VBScript Code Files - Updated in 2015, by Dr. Herong Yang