Introduction to Windows Script Host

WIndows Script Host is a core component of the Windows 2000 and is also available for earlier versions of Windows. To ensure that WSH is installed on your computer, type cscript at a command prompt. You should see version information for WSH as well as usage details
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Usage: CScript scriptname.extension [option...] [arguments...]

Options:
 //B         Batch mode: Suppresses script errors and prompts from displaying
 //D         Enable Active Debugging
 //E:engine  Use engine for executing script
 //H:CScript Changes the default script host to CScript.exe
 //H:WScript Changes the default script host to WScript.exe (default)
 //I         Interactive mode (default, opposite of //B)
 //Job:xxxx  Execute a WSF job
 //Logo      Display logo (default)
 //Nologo    Prevent logo display: No banner will be shown at execution time
 //S         Save current command line options for this user
 //T:nn      Time out in seconds:  Maximum time a script is permitted to run
 //X         Execute script in debugger
 //U         Use Unicode for redirected I/O from the console

The key components of Windows Script Host are:

Windows scripts can be run with either WScript CScript, and most of the time the application you use depends on your personal preference. However, you'll find that WScript works best for scripts that interact with users. For tasks that you want to automate or run behind the scenes, you'll probably prefer CScript, with which you can suppress output and prompts for batch processes.

The Basic Windows Script Host tasks are:

Windows Script Host Architecture

Core Model

WSH provides the key functionality to interact with the operating system. In WSH, objects are simply named containers that you'll use to work with operating system components. For example, you'll use WSHNetwork object to access and configure network resources, like printers and drives.

Each object has properties and methods that are used to perform certain types of tasks. Properties are attributes of an object that you can access. Methods are procedures that you can use to perform operations. The following table contains a summary of the WSH object model. The WSH hierarchy can be broken down into two broad categories:

method. Used to create and manage URL shortcuts.
Exposed Objects
Object Description
WScript Top-level object that provides access to core objects and other functionality such as object creation.
WScript.WshNetwork    Automation object used to access and configure network resources, like printers and drives. Also provides user, domain, and computer information.
WScript.WshShell Automation object that provides access to the environment and file folders.
Non-exposed Objects
Object Description
WshArguments Accessed through WScript.Arguments. Obtains command-line arguments.
WshCollection Accessed through WshNetwork.EnumNetworkDrives or WshNetwork.EnumPrinterCollection. Used for iteration through a group of items, such as printers or drives.
WshEnvironment Accessed through WshShell.Environment. Allows to work with environment variables.
WshShortcut Accessed through WshShell.CreateShortcut. Used to create and manage file shortcuts.
WshSpecialFolders Accessed through WshShell.Folder. Used to work with file folders.
WshUrlShortcut Accessed through WshShell.CreateShortcut

More on scripting hosts

To execute Windows scripts, you'll use one of the two scripting hosts available, either WScript or CScript. You can work with both of these hosts in much the same way, just enter wscript or cscript followed by the pathname of the script you want to execute:
c:\scripts\> cscript my_first.js
Several file extensions are mapped for use with the scripting hosts. These file extensions are: A limitation of .js and .vbs is that they can only contain JScript or VBScript statements, respectively, and you cannot mix and match. That's why the .wsf files are useful. You can use .wsf files to create WSH jobs, these jobs can combine multiple types of scripts and can also include type libraries containing constants. Windows scripts can also use .wsh files. These files contain default settings for scripts, such as timeout values and script paths. Because of the introduction of .wsf files and direct in-script support for most script properties, .wsh files are rarely needed.

These are several small examples of Windows scripts:

References: