Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between Wscript and Cscript running scripts

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "what are the differences between Wscript and Cscript running scripts". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Run in window, run in WSCRIPT; command line, CScrip

Because cscript puts the output in the console, it can be redirected to facilitate the program to call

Wscript output directly with windows is suitable for debugging programs and writing gadgets without cmd under windows cscript output will flash in most cases, the options listed in the following table apply to WScript.exe and CScript.exe. Exceptions are annotated.

Parameter description

/ / B batch mode; hides the display of user prompts and script errors on the command line. The default mode is interactive mode.

/ / D Open the debugger.

/ / E:engine executes the script using 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, WScript.exe is assumed to be the default application.

/ / I default. Interactive mode; allows user prompts and script errors to be displayed. As opposed to batch mode.

/ / Job: runs the specified JobID from a .wsf file.

/ / logo defaults. Displays the title. Contrary to nologo.

/ / nologo prevents the execution title from being displayed at run time. The default setting is logo.

/ / S saves the user's current command line options.

/ / T:nn enable timeout: the maximum number of seconds a script can run. The default setting is unlimited. The / / T parameter prevents the script from overexecuting by setting a timer. When the execution time exceeds the specified value, CScript interrupts the script engine with the IActiveScript::InterruptThread method and terminates the process.

/ / U is used for Windows NT and Windows 2000 to force command line output in Unicode format. CScript cannot decide whether to output as 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 any COM objects required by the script. It is also the responsibility of the script host to determine which language engine to use when running the script. For example, if the script has a .vbs extension, the script host will load the VBScript language engine and begin working with that engine to execute the code.

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

The two exceptions lie in how you interact with a script; that is, how you get information into a script (input) and how the script displays information it has retrieved (output). In general, CScript receives input from 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 that does not require user interaction, you can 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 either 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 of messages runs much differently under CScript (where the messages are displayed as individual lines within a command window) and WScript (where the messages are displayed as a series of message boxes). If you are interested in seeing the difference for yourself, copy the script into Notepad, save it with a .vbs file extension, and then run it under both CScript and WScript. (For more information about running scripts under a script host, see "Running WSH Scripts" later in this chapter.)

The copy code is as follows:

Wscript.Echo "Line 1."

Wscript.Echo "Line 2."

Wscript.Echo "Line 3."

Wscript.Echo "Line 4."

This is the end of the content of "what are the differences between Wscript and Cscript running scripts". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report