"WScript" Runtime Object Hierarchy

This section describes WSH runtime objects: WScript and its properties. A tutorial example is provided on how to use WScript.StdIn and WScript.StdOut.

Like any other scripting environment host, WSH provides several nice runtime objects to allow your VBScript code to interact with the environment:

Let's try a simple example with the StdIn and StdOut properties of the WScript:

'  StdIn_StdOut.vbs
'- Copyright (c) 1998 HerongYang.com. All Rights Reserved.

   Dim StdIn, StdOut
   Set StdIn = WScript.StdIn
   Set StdOut = WScript.StdOut

   Dim cmd
   Do While True
      StdOut.WriteLine
      StdOut.WriteLine "Herong, what can I do for you?"
      cmd = StdIn.ReadLine
      If cmd = "Nothing" Then Exit Do
      StdOut.WriteLine "Sorry, I am not programmed to do that."
   Loop

Now run it with cscript.exe:

C:\herong>cscript StdIn_StdOut.vbs

Herong, what can I do for you?
Make me rich
Sorry, I am not programmed to do that.

Herong, what can I do for you?
Make me happy
Sorry, I am not programmed to do that.

Script execution time was exceeded on script 
   "C:\herong\StdIn_StdOut.vbs".
Script execution was terminated.

The code worked nicely. But it was terminated because of the execution time limit. You need to run it with a longer limit specified in the command line, like //T:600 for 10 minutes:

cscript //T:600 StdIn_StdOut.vbs

Note also this example can not be executed with the wscript.exe host, because it does not support StdIn and StdOut properties. Running "wscript StdIn_StdOut.vbs" will result an error: "The handle is invalid"

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)?

 "cscript.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

 Full Version in PDF/EPUB