CIS Logo SVC Logo

   Computing & Information Systems


Schoology Facebook        Search CIS Site      Tutorials

What is WSH?


Windows Script, also called Windows Script Host (WSH), allows you to write scripts to automate tasks on a Windows computer much like Unix shell scripts do in a Unix environment. WSH is much more powerful than the batch file programs that used to be used in DOS. Some version of WSH is included in all recent versions of Windows. WSH includes both VBScript and JScript scripting engines. These web pages only discuss using VBScript. Objects are used extensively in WSH.

A Simple Example

The following is a very simple WSH script written in the VBScript language. Copy these lines of code into Notepad or another text editor and save in a file named hello.vbs. Note that the vbs extension identifies the language used as VBScript.

' Filename:  hello.vbs
' Author:  Br. David Carlson
' Date:  August 3, 2001
' This WSH script simply echos an hello message to the screen.

WScript.Echo "Hello.  This is a simple example of a WSH script."
WScript.Echo "This particular script is written using VBScript."

The lines that start with a single quote are comments, of course. The 2 lines of actual code both use the Echo method (function) on the WScript object. In each case, a message is displayed on the screen.

Running a WSH Script

There are several ways of running a script such as the hello.vbs script. You can simply double click on the hello.vbs file in My Computer. This runs the program in the Wscript GUI-based utility. Each of the above 2 messages is displayed in a dialog window on the screen. You have to click on the OK button after reading each message.

If you go to a command prompt you can run your script with either the Wscript utility or the command-line Cscript utility. For example, to run the above script under the Cscript utility, enter:
cscript hello.vbs
Each message is simply displayed on a new line in the DOS box. There is no OK button on which to click. You can also run your script using Wscript by entering the following at the command line:
wscript hello.vbs
The result is the same as when double-clicking on the script file in My Computer. With scripts that use commands to send output to a dialog box, the output will obviously be in a dialog box whether Cscript or Wscript is used. It is with echo that the output appears differently. (Msgbox and Popup are two ways to place output in a dialog box. Msgbox is described in the Reporting on Network Drives section and Popup in the Another Way to Report on Network Drives section.)

Note that scripts can also be run at set times by using the Windows Task Scheduler (at least, if it makes sense to run the script automatically at a set time). The Task Scheduler can usually be found under Accessories, System Tools, Scheduled Tasks.

Back to main Windows Script Host page

Author: Br. David Carlson
Last updated: February 11, 2007