How the Components of the WSH Environment Work Together

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Components in the WSH environment must interact with one another to run scripts. These interactions include the following:

Script Host and Script File   When a script host is invoked to run a script, it begins by examining the file-name extension of the script file. The script host searches the registry to determine the scripting language engine that corresponds to the extension and then loads the script file in preparation for interpreting its instructions. All this happens before a single line of code is actually executed.

Script Host and Scripting Language Engine   After determining the language used in the script, the script host works with the corresponding scripting language engine to interpret the instructions in the script. The script host communicates with the scripting language engine through the Windows Script Interfaces. The entire script is read and checked for syntax errors before any code is executed. For example, the following script has an error in line 3; the syntax of the If Then statement is incorrect:

Wscript.Echo "Line 1." Wscript.Echo "Line 2." If x = 1     Wscript.Echo "X is equal to 1." End If 

You might expect that the script would execute lines 1 and 2 and thus display two messages before encountering the error on line 3. Instead, the error is caught in the pre-execution syntax check. Instead of displaying two messages, the script displays the error message "Expected Then ."

WScript Library and COM Objects   When instructions within a script indicate that a COM object is to be used, the built-in WScript library interacts with the COM runtime on behalf of the script.

Note

  • Many scripting languages provide the ability to interact with COM objects directly, in which case WScript is not part of the interaction. Because this chapter is about WSH, the examples use the WScript CreateObject and GetObject methods. However, VBScript also enables you to bind to COM objects and has a slightly easier syntax. Consequently, the VBScript functions are used in nearly all the other scripts in this book. For a more thorough comparison of the two functions, see "VBScript Primer" in this book.

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net