Running Scripts Using Cscript.exe

To use Cscript.exe, open a Command Prompt window and type a Cscript command line. CScript uses the following syntax:

cscript [script name] [host options...] [script options]
 

Each parameter is optional; however, you cannot specify script options without specifying a script name. If you do not specify parameters, Cscript displays the Cscript syntax and the valid host parameters.

Cscript.exe supports the host parameters shown in the following table.

Parameter Description
//I Interactive Mode: allows display of user prompts and script errors (this is the default, and the opposite of //B).
//B Batch Mode: suppresses command-line display of user prompts and script errors.
//T:nn Enables time-out: the maximum number of seconds the script can run. The default is no limit. (See the text following this table for more information on this parameter.)
//logo Displays a banner (default; opposite of //nologo).
//nologo Prevents display of an execution banner at run time.
//H:Cscript or //H:Wscript Registers Cscript.exe or Wscript.exe as the default application for running scripts. If neither is specified, Wscript.exe is assumed as the default.
//S Saves the current command-line options for this user.
//?     Shows command usage (same as with parameters).

The //T parameter prevents excessive execution of scripts; it does this by setting a timer. When execution time exceeds the specified value, Cscript interrupts the scripting engine using the IActiveScript::InterruptThread method and terminates the process.

A Cscript Example

Several sample scripts are installed when you install the final release of the Windows Scripting Host. These are also available for download at:

http://www.microsoft.com/management/wsh.htm

Suppose, for the purposes of this example, that you have copied the Chart.vbs sample script to the following folder on your computer:

c:\sample scripts\chart.vbs

You can run the script with and without a logo, as follows:

  1. Click Start, point to Programs, and click Command Prompt.
  2. Type the following commands at the command prompt (if your sample scripts are located in a different folder, these lines should be modified accordingly):
    cscript //logo c:\攕ample scripts擻chart.vbs
    cscript //nologo c:\攕ample scripts擻chart.vbs
    

When Windows Scripting Host ships with Windows NT 5.0, you will no longer need to provide the script file extension. Instead, you can type just the script name, or double-click the script in Windows Explorer.