Using VBScript with Windows Script Host

This section provides tutorial example on how to run a simple VBScript code file with the Windows Script Host tool.

Windows Script Host (WSH) is a Windows administration tool that provides host environments for several scripting languages including VBScript.

VBScript codes included in script files will be executed by WSH directly on the Windows operating system.

If you are running a Windows XP system, you can try these steps to run a simple VBScript code with Windows Script Host:

1. Create a script file called hello.vbs:

   WScript.StdOut.WriteLine "Hello World! - VBScript in WSH"

2. Run hello.vbs with the "cscript" command in a command window:

C:\herong>cscript hello.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Hello World! - VBScript in WSH

Congratulations. You have successfully written a VBScript code for the host environment provided by WSH!

What happened here was:

Table of Contents

 About This Book

Introduction of VBScript - Visual Basic Scripting Edition

 What Is VBScript?

 Using VBScript with Internet Explorer

 Using VBScript with Internet Information Services

Using VBScript with Windows Script Host

 Using Visual Basic with Microsoft Access

 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)

 References

 PDF Printing Version