Wscript and Cscript The difference between running scripts _vbs

Source: Internet
Author: User

The difference between WScript and cscript

The window runs, WSCRIPT, the command line runs, Cscrip;
cscript because you put the output in the console, you can redirect it to facilitate program invocation.
WScript directly with the window output suitable for debugging and writing gadgets in Windows without cmd CScript output will flash through most cases, the options listed in the following table apply to WScript.exe and CScript.exe. Exceptions are commented.

Parameter description
B batch mode; Hide user hints and script errors displayed on the command line. The default mode is interactive mode.
D Open the debugger.
E:engine executes the script with the specified script engine.
H:cscript or//H:WScript registers CScript.exe or WScript.exe as the default application for running scripts. If not specified, the WScript.exe is assumed to be the default application.
I default. interactive mode; Allow user hints and script errors to be displayed. is the opposite of batch mode.
Job:<jobid> runs the specified Jobid from the. wsf file.
Logo default. Displays the title. Contrary to the nologo.
Nologo prevents the execution caption from being displayed at run time. The default setting is the logo.
S saves the user's current command-line options.
T:NN Enable timeout: Maximum number of seconds that a script can run. The default setting is unrestricted. The T parameter prevents the script from executing excessively by setting the timer. When the execution time exceeds the specified value, CScript interrupts the script engine with the Iactivescript::interruptthread method and terminates the process.
U for Windows NT and Windows 2000, forcing the command line to output in Unicode format. CScript cannot determine whether to output in Unicode or ANSI; the default setting is ANSI.
X starts the program in the debugger.
//?

Microsoft's Explanation:

Script Hosts
The script host initiates and coordinates the running of your script; It reads your script file and interacts with components of the WSH environment and no COM objects by the script. It is also the responsibility of the script host to determine which language the script. For example, if the script has a. vbs extension, the script host would load the VBScript language engine and begin working With this engine to execute the code.

The WSH environment includes two script hosts:the console-based and CScript gui-based. The two script hosts provide nearly identical capabilities, and in most cases, it does not matter the script Host s use to run your scripts.

The two exceptions lie in how to interact with a script; That's, how to get information into a script (input) and how the script displays information it has retrieved (output). In general, CScript receives input to the command prompt and displays output in a command window. WScript, by contrast, receives input through a graphical dialog box and displays output in a graphical message box.

Otherwise, the two script hosts are largely identical:if you have a script this does not require user interaction, CA N run that script under either CScript or WScript. For example, the following script maps a network drive. Because it neither requires input nor displays output, it runs exactly the same under script Host:

Set objnetwork = WScript.CreateObject ("wscript.network") objnetwork.mapnetworkdrive "G:", "\\atl-fs-01\Sales"
On the other hand, the following script which displays a series to messages runs much differently under CScript (where the Messages are displayed as individual lines within a command window) and WScript (where the messages are as a SE Ries of message boxes). If you are are interested in seeing the difference for yourself, copy of the script into Notepad, save it with a. vbs file Extens Ion, and then run it under both CScript and WScript. (For more information about running scripts under a script host, the "Running WSH" scripts later in this chapter.)

Copy Code code as follows:

WScript.Echo "Line 1."
WScript.Echo "Line 2."
WScript.Echo "Line 3."
WScript.Echo "Line 4."

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.