Introducing the WSH

Administrators with a previous background in JavaScript or Visual Basic programming will find the WSH easier to learn than nonprogrammers. The WSH is shipped with two built-in scripting languages, JScript and VBScript. JScript is Microsoft implementation of JavaScript, and VBScript is a scripting version of the Visual Basic language. Both JScript and VBScript have their origins in Web development but have been modified by Microsoft to allow them to function outside of the Internet Web browser.

The Advantages of Using the WSH

The WSH can often be used to develop scripts that cannot be written using Shell scripting. For example, Shell scripts cannot directly access the Windows XP registry, whereas the WSH object model allows WSH scripts to read, change, and delete registry keys and values. In addition, the WSH has more advanced file and folder administration capabilities. While Windows Shell scripting can script many Windows tasks, the more complex the task becomes, the more likely that the WSH is the better scripting language to use.

The WSH offers several capabilities not provided by Shell scripting, including:

  • The ability to display and collect user input using pop-up dialogs

  • The ability to run on all Windows operating systems since Windows 95, making WSH scripts more portable

  • The ability to manipulate the Windows desktop, taskbar, and toolbars

  • The ability to work directly with Windows applications by accessing their object models

Examining the WSH Architecture

The WSH is a 32-bit Windows application. It is made up of a number of separate components, each of which performs a specific function. These components include:

  • A core object model

  • Two execution environments

  • Two scripting engines

These three sets of components fit together as shown in Figure 14.1.

click to expand
Figure 14.1: The WSH is made up of a number of separate components

The WSH core object model provides access to Windows objects, allowing direct control over a number of Windows XP resources such as the registry, desktop, file system, and network resources. Each object exposed by the core object model has associated methods and properties that WSH scripts can execute or modify. WSH scripts require an execution host to provide an environment in which they can execute. The WSH supplies two execution hosts, as listed below.

  • CScript.exe. Supports text-based scripts that run in command-line mode and is usually used to run scripts that execute in the background and require no user interaction.

  • WScript.exe. Provides the ability to run WSH scripts that communicate with the user using pop-up graphical dialogs.

Figures 14.2 and 14.3 demonstrate the WSH WScript execution host support for pop-up dialogs. This capability allows administrators to write scripts that are more user-friendly.


Figure 14.2: A GUI pop-up dialog that prompts the user to select a response

click to expand
Figure 14.3: A GUI pop-up dialog that allows the user to provide text input

Aside from WScript's support for pop-up dialogs, the CScript and WScript execution hosts provide identical functionality.

WSH execution environments depend on script execution engines to process and interpret scripts statements. The WSH ships with two scripting engines, one for JScript and one for VBScript. Each of these scripting engines is specifically designed to interpret scripting statements particular to its defined language.

Note 

To learn more about the WSH, JScript, and VBScript, refer to the Microsoft Windows Scripting Technologies Web site at http://msdn.microsoft.com/scripting.

Working with JScript and VBScript

WSH script files are created using a particular scripting language and are then saved using a file extension appropriate for that language. For example, WSH scripts written in JScript are saved as plain text files with a .js file extension. WSH scripts written in VBScript are saved with a .vbs file extension.

Note 

Third-party software developers have created WSH-compatible scripting languages for Perl and Python.

When writing scripts in JScript or VBScript, administrators must be careful to closely follow the specific rules and syntax for each scripting language. Despite very different origins, JScript and VBScript provide equivalent scripting capabilities. JScript will be easier to learn for administrators with JavaScript experience, whereas VBScript will be easier to learn for administrators with Visual Basic programming experience.

The WSH also provides the ability to combine more than one scripting language into a single script file known as a WSF (Windows Script File) with a .wsf file extension. WSFs use a subset of the XML (Extensible Markup Language) to format WSF scripts and to identify which portions of the script are written in JScript and which portions are written in VBScript.

Note 

Administrators interested in gaining advanced knowledge of the WSH should read Microsoft Windows Shell Scripting and WSH Administrator's Guide by Jerry Lee Ford Jr., published by Premier Press, 2001.

For more information about VBScript, read Learn VBScript in a Weekend by Jerry Lee Ford Jr., published by Premier Press, 2002.

For more information about JavaScript and JScript, read Learn JavaScript in a Weekend by Jerry Lee Ford Jr., published by Premier Press, 2001.



Microsoft Windows XP Professional Administrator's Guide
Microsoft Windows XP Professional Administrators Guide
ISBN: 1931841969
EAN: 2147483647
Year: 2005
Pages: 358

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