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:where the terms are defined as follows:cscript [host options...] [script name] [script options and parameters]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.
- Host options enable or disable various Windows Script Host features. Host options are preceded by two slashes (//).
- Script name is the name of the script file, complete with extension and any necessary path information, such as: d:\admin\vbscripts\chart.vbs.
- Script options and parameters are passed to the script. Script parameters are preceded by a single slash (/).
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 Default. Displays a banner (opposite of //nologo). //nologo Prevents display of an execution banner at run time. //H:CScript or
//H:WScriptRegisters 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.
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/scriptingSuppose, 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:
- Choose the MS-DOS® operating system command prompt from Programs on the Start menu.
- 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