About Windows Scripting Host

This topic contains conceptual information about Windows Scripting Host, including

Windows Scripting Host can be run from either the Windows-based host (Wscript.exe), or the command shell-based host (Cscript.exe).

The Benefits of Windows Scripting Host

Windows Scripting Host (WSH) brings simple, powerful, and flexible scripting to the 32-bit Windows platform.

Implementing More Powerful Scripts

Previously, the only native scripting language supported by the Windows operating system was the MS-DOS® command language (Batch Files). Although the MS-DOS® command language is fast and small, MS-DOS has limited features compared to VBScript and JScript. Today, ActiveX™ scripting architecture allows users to take advantage of powerful scripting languages such as VBScript and JScript. And MS-DOS command scripts are still supported.

Windows Scripting Options

Microsoft currently provides three hosts for running these scripting languages across the Windows platform:

Microsoft Internet Explorer enables scripts to be executed on client machines from within HTML pages.

IIS supports Active Server Pages, which enables scripts to be run on Web servers; in other words, it enables server-side scripting over the Internet or an intranet.

Windows Scripting Host enables scripts to be executed directly on the Windows desktop or command console, without the need to embed those scripts in an HTML document. Scripts can be run directly from the desktop simply by clicking a script file, or from the command console. Windows Scripting Host provides a low-memory scripting host that is ideal for non-interactive scripting needs such as logon scripting, administrative scripting, and machine automation.

Windows Scripting Host Architectural Overview

The Windows Scripting Host serves as a controller of ActiveX Scripting engines, just as Microsoft Internet Explorer does. Because the scripting host is not a full Internet browser, it has a smaller memory footprint than Microsoft Internet Explorer; therefore, WSH is appropriate for performing simple, quick tasks.

The scripting host reads and passes the specified script file contents to the registered script engine by use of the IActiveScriptParse::ParseScriptText method provided by the script engine.

The scripting engine does not use the SCRIPT tag or LANGUAGE attribute (used in HTML); instead it relies on the file name extension. This way, the script writer need not be familiar with the exact ProgID of various script engines. The scripting host maintains a mapping of the script extensions to ProgIDs and uses the Windows association model to launch the appropriate engine.

Setting Per Script Properties and the .WSH File

By using the Wscript.exe Properties page, you are able to set global scripting options for all scripts that are executed on the local machine. However, you also have the ability to set individual script settings on a per script basis. These script settings allow you individual control over how specific scripts will execute, creating a .wsh file for that script. In order to set per script properties and create a .wsh file, simply right click on the script file within the Explorer application and choose Properties. Set specific script properties, such as the amount of seconds the script should execute, and choose OK. You will notice that a .wsh file is created in the same directory as the original script and is created using the same name as the original script.

What is a .WSH file?

A .wsh file contains per-script settings for script files for Windows Scripting Host. It is like a PIF file for 16bit applications.

How to use a .WSH file

Once you have set per script properties, a .wsh file will be created in the same directory as the original script, and uses the original name of the script followed by a .wsh extension. Double click on the .wsh file icon in Explorer or use CScript.exe or WScript.exe at the command prompt to execute that script. For example,

C:\> cscript Myscript.wsh

How the .WSH file helps administrators

The administrator creates a per-script .wsh that specifies settings that the script will use when executed. The administrator can create several versions of the .wsh file for a variety of users within their organization.

How to create a .WSH file

Right-click on the script file (.vbs or .js) you would like to change properties for. Select the Properties option on the context menu. Change settings within the properties page and select OK or Apply. You will then see a .wsh file created using the same name as the original script that you right-clicked on.

What data is stored within the .WSH file?

The .wsh file is a simple text file and its format is similar to that of an .inf file. Below is an example of a .wsh file:


[ScriptFile]

Path=C:\WINNT\Samples\WSH\showprop.vbs

[Options]
Timeout=0
DisplayLogo=1
BatchMode=0

The Path setting in the [ScriptFile] section points to the script file that this .wsh file affects. The settings found under the [Options] section correspond to the setting in the [Script] tab within the Properties dialog box.

How the .WSH file works

When you double click on the .wsh file, or execute the .wsh from the command line, Cscript.exe or Wscript.exe reads the .wsh file to determine the specific script settings that should be used to execute the specific script file. CScript/WScript will execute the original script passing in the properties that are defined within the .wsh file. It is important to note that you must have the original script file present when executing the .wsh file. If the .wsh file fails to execute the script, check the Path= entry in the .wsh file to ensure it is pointing to the correct script you are attempting to run.


© 1997 by Microsoft Corporation. All rights reserved.