How to Run VBS/JS script from cmd/Command Prompt


Cscript.exe is a command-line version of the Windows Script Host that provides command-line options for setting script properties.
With Cscript.exe, scripts can be run by typing the name of a script file at the command prompt. Windows Script Host supports scripts written in VBScript or JScript. The script engine uses file extensions (that is, .vbs for VBScript and .js for JScript) to identify the script.

The syntax for running scripts at the command prompt with the command-line-based script host is as follows
cscript [script name] [host options] [script arguments]

Where:

·         script name is the name of the script file, including the file name extension and any necessary path information.
·         host options are the command-line switches that enable or disable various Windows Script Host features. Host options are always preceded by two slashes (//).
·         script arguments are the command-line switches that are passed to the script. Script arguments are always preceded by one slash (/).
Note
  • Each parameter is optional; however, script arguments cannot be specified without specifying a script. In this case, Cscript.exe displays the Cscript.exe syntax and the valid host options.
  • The command-line-based script host supports the following host options: 

 


Parameter
Action
//B
Specifies batch mode, which does not display alerts, scripting errors, or input prompts.
//D
Turns on the debugger/Enables active debugging
//E: engine
Specifies the scripting language that is used to run the script.
//H:cscript or //H:wscript
Registers either Cscript.exe or Wscript.exe as the default script host for running scripts. If neither is specified, the default is Wscript.exe.
//I
Specifies interactive mode, which displays alerts, scripting errors, and input prompts. This is the default and the opposite of //B.
//Job: xxxx
Runs the job identified by xxxx in a .wsf script file.
//Logo
Specifies that the Windows Script Host banner is displayed in the console window before the script runs. This is the default and the opposite of //Nologo.
//Nologo
Specifies that the Windows Script Host banner is not displayed before the script runs.
//S
Saves the current command-prompt options for the current user.
//T: nnnnn
Specifies the maximum time the script can run (in seconds). You can specify up to 32,767 seconds. The default is no time limit.
//X
Starts the script in the debugger.
//? 
Displays available command parameters and provides help for using them (this is the same as typing Cscript.exe with no parameters and no script).The time out option (//T:nnnnn) prevents excessive execution of scripts by setting a time limit. When execution time exceeds the specified value, Cscript.exe interrupts the script engine and stops the process.
The time out option (//T:nnnnn) prevents excessive execution of scripts by setting a time limit. When execution time exceeds the specified value, Cscript.exe interrupts the script engine and stops the process.