WSH » Introduction

Download free PDF version

Welcome to the DevGuru Windows Script Host Quick Reference guide. This is a valuable reference source that explains and provides comprehensive, working examples of code for all of the objects, collections, elements, methods, and properties belonging to WSH version 2.0.

Microsoft currently offers three hosts for running scripting language code.

They are:

  • Internet Explorer (IE)
  • Internet Information Server (IIS)
  • Windows Script Host (WSH)
The Internet Explorer, and to a slightly lesser extent, the Internet Information Server are certainly well known to developers. However, many developers may not be familiar with the Windows Script Host. WSH is a very useful tool that allows you to directly run VBScript, JScript and XML encoded scripts natively within the operating system.

Windows Script Host comes free with Windows 2000 and 98. If you have Windows 95 or NT, WHS can be downloaded for free from Microsoft as part of a package called "Windows Script 5.1".

The download contains:
  • VBScript version 5.1
  • JScript version 5.1
  • Windows Script Components
  • Windows Script Runtime version 5.1
  • Windows Script Host version 2.0
(By the way, Microsoft has also offered a Windows Script Host beta version 5.5.)

Please go to the DevGuru Resources Page to download Windows Script 5.1.

Note: To obtain the full value of WSH 2.0, you need to have Internet Explorer 4.0 or higher installed.

Once WSH is installed on your system, it is very easy to run a VBScript or JScript program. All you have to do is simply double-click on any file that has the .js or .vbs extension and that file will be executed within the Windows Script Host environment. After the scripts have been thoroughly tested, you can schedule their execution through the Windows Task Scheduler. Indeed, Windows Script Host, in conjunction with the Task Scheduler, is ideal for setting up batch processing. For example, you can have Windows run WSH and the script automatically, such as each time Windows starts up, or you could set up a batch job that runs daily.

Please remember that WSH can only run VBScript and JScript files that are .vbs or .js. It does not run files. If you wish to run the VBScript code contained in an file in the WSH environment, you need to remove all of the HTML tags, the >% and %< tags, and rename the file with a ".vbs" extension. Also, remove all references to any of the ASP intrinsic objects. A Response.Write can be replaced with WScript.Echo. In essence, you are creating a stand alone VBScript file or JScript file.

In addition to files with .vbs or .js extensions, WSH 2.0 also recognizes the .wsf extension. FIles with the .wsf extension are scripts encoded in XML format. The advantages of using XML encoded scripts include the ability to use multiple scripting languages within the same script file, write reusable code and specify references to external type libraries.

WSH offers a suite of eight objects that can be used for network, registry and shell manipulation. These objects offer you greater functionality than that which is available when using either JScript or VBScript alone.

An interesting aspect of WSH is that it contains two platform-specific executables, cscript.exe and wscript.exe. The echo (output) for cscript is to a command window (via a Win32 console application). While the echo (output) for wscript is to a graphical message box (via Windows). Just remember that the c stands for console and the w for Windows. For a full list of arguments, enter "cscript /?" or "wscript /?" at a command prompt.

Windows Script Host is a technology worth adding to your repertoire.