Microsoft® Windows® Script Host
Running Scripts with CScript.exe
 WSH Tutorial
Previous
Next

 

CScript.exe is the version of Windows Script Host that enables you to run scripts from the command prompt. CScript.exe provides command-line switches for setting script properties. To use CScript.exe, type a command line at the command prompt using the following syntax:
cscript [host options...] [script name] [script options and parameters]
where the terms are defined as follows: 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 options shown in the following table.

ParameterDescription
//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 Default. Displays a banner (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).
//E:engine Executes the script with the specified scripting engine.
//D Turns on the debugger.
//X Launches the program in the debugger.
//Job:<JobID> Runs the specified JobID from the .wsf file.

The //T parameter prevents excessive execution of scripts 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 Script Host. These are also available for download at: http://msdn.microsoft.com/scripting

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. Choose the MS-DOS® operating system command prompt from Programs on the Start menu.
  2. Enter the following commands at the command prompt (modify accordingly if your sample scripts are located in a different folder):
cscript //logo c:\"sample scripts"\chart.vbs
cscript //nologo c:\"sample scripts"\chart.vbs