Yes, Virginia, these are the same VBScript and JScript that you have embedded into your Web pages, and they offer all the same capabilities. Applets written in either language have built-in object-oriented access to the file system, network settings, registry, and Windows shell elements. Both languages are COM and ActiveX aware, allowing you to drive “COMpliant” applications and use multitudes of available third-party programming tools in your scripts. The WSH is standard equipment on Windows 98, Windows 2000, and Windows NT Service Pack 4. Windows 95 machines can be easily updated via a download available from Microsoft . So, you can pretty safely assume that it’s installed on newer machines; if not, it’s an easy update.
The underlying technology at work is known as “Active Scripting.” It defines a standard method for any application to become a scripting host by launching the correct engine for a received script type and feeding the engine script one line at a time. Engines are implemented as ActiveX components and allow an application to become scripting-enabled without dependency on scripting language—indeed without the application being aware of the script content at all. The engine itself handles all underlying language-dependent issues. The only caveat is that a custom engine must be built for each language supported, and it seems likely that only engines for Microsoft-preferred languages will be standard equipment on Windows.
Scripts are saved in plain text format and can be created using any text editor, so there’s no new programming environment to learn. The script’s file extension used determines what engine is used to execute the script: .vbs for VBScript and .js for JScript. Plain text files are infinitely portable; however, “real” developers may find themselves frustrated by the lack of an IDE, and there are no plans to introduce IntelliSense into new versions of Notepad.
In addition to standard UI methods, applets can be launched as command-line parameters to Wscript.exe (the Windows-based scripting host) or Cscript.exe (the command-prompt scripting host). Only a handful of configuration options are supported, via command-line switches, property page settings, or special configuration files with the extension .wsh. The various options are detailed in the table below:
|Comm and Switch||Property Page Settings||WSH File Setting||Description|
|Path||Found under the “ScriptFile” section, this setting specifies the path and filename of the script file that will be launched when the WSH file is executed.|
|//B||BatchMode||Scripts executed in Batch mode have all output suppressed and will not prompt users for any input.|
|//logo||Display logo when script executed in MS-DOS prompt||DisplayLogo||This setting controls whether a two-line “Windows Scripting Host” banner including version information is displayed in the first two lines of the MS-DOS window when a script is executed.|
|//T:n||Stop Script After Specified number of seconds||Timeout=n||Specifies a time-out interval for the script in seconds. The script will run for n seconds before being terminated. Setting this to a value of 0 means there will be no time-out.|
As mentioned, applets also can be configured via special WSH settings files. These special executable text files behave similarly to PIF files and have a structure identical to INI profile files: section titles enclosed in square brackets and lines of setting and value combinations. Running a WSH file will launch the script file indicated in the Path setting found in the ScriptFile section. Multiple entries here are ignored, as multiple scripts cannot be chained together using this mechanism. The Options section specifies all settings available from the Script tab in the Properties window.
Although WSH files can be edited using any text editor, Microsoft hasn’t made getting there easy. There is no Edit option on the Shortcut menu, and no Open With option with a shift-right-click menu, so editing these files can be tricky. However, Windows will automatically create a WSH file for any script that has its settings altered from the defaults on the Script tab of the Properties dialog box, and only settings available from the Script tab are configurable using WSH files, so editing may never be needed.
A real step forward
The Windows Scripting Host provides a useful alternative to antiquated MS-DOS batch files using popular and accessible, yet powerful, languages to automate tasks. The easy object-oriented access to system features is a refreshing change from the propeller-headed mindset of the past. Still, until more language alternatives are available and packaged into Windows distributions (don’t hold your breath), fully utilizing the capabilities of the WSH system will demand that you subscribe to Microsoft’s development vision.
We’ve listed several Web resources where you can find out more about WSH and new scripting options in the Windows environment. Also, check the Samples folder under your Windows folder for some VBScript and JScript examples to play with.
- Microsoft’s WSH information zone, includes sample code, a programmer’s reference, technical white papers, and downloads: msdn.microsoft.com/scripting/start.htm .
- Jump into a series of scripting articles at: msdn.microsoft.com/voices/scripting.asp .
- Glazier Systems’ Windows Script Host page offers a searchable FAQ section, sample code, Chat/IRC, and a beginner’s section: wsh.glazier.co.nz/default.asp .