Run a VBScript / Windows Scripting Host (WSH) script.
VBScripts can be run from either the CMD shell or PowerShell, or launched using a Windows shortcut.
'cscript' runs entirely in the command line and is ideal for non-interactive scripts.
'wscript' will popup Windows dialogue boxes for user interaction.
Syntax cscript [options...] [ScriptName.vbs] [script_arguments] wscript [options...] [ScriptName.vbs] [script_arguments] Options: ScriptName.vbs : Text file containing VBScript commands to execute. You must include the .vbs extension. //T:nn Timeout script after nn seconds. //nologo Hide startup banner. //Logo or Display banner (default) //I Interactive mode. The default, and the opposite of /b. //B Batch mode, which does not display alerts, scripting errors, or input prompts. //E:engine Use engine for executing script e.g. //E:jscript //H:CScript Change the default vbs script host to CScript.exe //H:WScript Change the default vbs script host to WScript.exe (default) //Job:xxxx Execute a WSF job. //S Save current command line options for this user. //D Starts the debugger. //X Execute script in debugger. //U Use Unicode for redirected I/O from the console.
It is important that all options are placed before the .vbs script (and any script arguments) in the command line, otherwise they will be passed as arguments to the script instead of being parsed by CSCRIPT.
It is recommended that you always include the .vbs file extension of the VB Script, if your PATHEXT variable includes .VBS it may not be required but you have to be sure this will be true on every machine where it is run and also that no conflicting files exist, e.g. a batch file with the same name.
Like many programs, cscript.exe will by default run as a 64 bit process on a 64 bit Operating System or it will run as a 32 bit process on a 32 bit Operating System. If your VBScript has any dependency on external programs, database connections etc this can make a difference.
To run a VBScript as a 32 bit process from a 64 bit OS use C:\Windows\SysWOW64\cscript.exe C:\scripts\demo.vbs
This can be done as shown below, although it is often better to put everything in a single script and use Functions to split up the blocks of code.
Set objShell = CreateObject("WScript.Shell")
objShell.run("cscript C:\scripts\demo.vbs")
The VB Script scripting environment is installed by default on Windows 98 and all later versions of Windows.
Run the VB script called myscript.vbs:
C:\> cscript //nologo myscript.vbs
If the line above is saved as a batch script, double clicking the batch file will run the VBScript file.
A one-line batch file that will run a vbscript with the same name as the batch file, saved in the same location just with a .vbs file extension:
@cscript //nologo "%~dpn0.vbs" %*
“Throw a lucky man in the sea, and he will come up with a fish in his mouth” ~ Arab proverb
.Exec - execute command.
.Run - Run an external Command.
.ShellExecute - Run an application in the Windows Shell.
Quit - Quit a VBScript.