Downloads
7530.zip

The scoop on the Windows Script file format

Microsoft is busy at work putting the finishing touches on Windows 2000 (Win2K). Similar to other parts of the OS, Windows Scripting Host (WSH) has undergone many improvements. The most significant enhancement is a new file type: the Windows Script (WS) file (with the filename extension .ws). The new file type supports the Extensible Markup Language (XML) and script. This month, I review the changes in WSH 2.0 and explain what you need to know to take advantage of WSH 2.0.

WSH 2.0 includes several new features and improvements: include-file support, multiple script-engine support, tools support, external-constant access, new runtime options, WSH object-model enhancements, and drag-and-drop support. Many of the WSH 2.0 enhancements rely on the XML elements that are part of the new WS file format. Let's look at the XML elements and the WS file in relation to the features in WSH 2.0.

Include Files
Include files provide a simple way to package (in a separate physical file) code that you reuse frequently in other WS scripts. Include files let you create script libraries so that you don't have to recreate identical code in every script you develop.

For example, suppose you have a collection of functions that you commonly use in scripts. Library.vbs in Listing 1, page 168, is a script library that contains a string variable (strMyString), a constant (MY_CONSTANT), and a couple of simple functions (NetworkInfo and ScriptInfo). The strMyString variable contains the text "Includes Rock!", MY_CONSTANT contains the integer value 123, and the two functions return strings. The NetworkInfo function returns information obtained from the properties that the Network object provides, and the ScriptInfo function returns information obtained from the properties that the WScript object exposes.

To access the variables and functions that library.vbs defines, you simply include library.vbs using the XML