溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Wscript和Cscript運(yùn)行腳本有哪些區(qū)別

發(fā)布時(shí)間:2021-09-30 15:15:49 來(lái)源:億速云 閱讀:136 作者:iii 欄目:開(kāi)發(fā)技術(shù)

本篇內(nèi)容介紹了“Wscript和Cscript運(yùn)行腳本有哪些區(qū)別”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

窗口中運(yùn)行,WSCRIPT;命令行中運(yùn)行,CScrip;
    cscript因?yàn)榘演敵龇胚M(jìn)了控制臺(tái) 所以可以對(duì)它重定向 方便程序調(diào)用
    wscript直接用窗口輸出 適合調(diào)試程序和編寫小工具 在windows下不用cmd的話cscript的輸出會(huì)一閃而過(guò) 大多數(shù)情況下,列在下表中的選項(xiàng)適用于 WScript.exe 和 CScript.exe。例外情況會(huì)加以注釋。

參數(shù)                      說(shuō)明
//B                       批處理模式;隱藏用戶提示和腳本錯(cuò)誤在命令行中的顯示。默認(rèn)模式是交互模式。
//D                       打開(kāi)調(diào)試程序。
//E:engine                用指定的腳本引擎執(zhí)行腳本。
//H:CScript或 //H:Wscript 將 CScript.exe 或 WScript.exe 注冊(cè)為運(yùn)行腳本的默認(rèn)應(yīng)用程序。如果未指定,則將 WScript.exe 假設(shè)為默認(rèn)應(yīng)用程序。
//I                       默認(rèn)。交互模式;允許顯示用戶提示和腳本錯(cuò)誤。與批處理模式相反。
//Job:<JobID>             從 .wsf 文件運(yùn)行指定的 JobID。
//logo                    默認(rèn)。顯示標(biāo)題。與 nologo 相反。
//nologo                  防止在運(yùn)行時(shí)顯示執(zhí)行標(biāo)題。默認(rèn)設(shè)置是 logo。
//S                       保存該用戶的當(dāng)前命令行選項(xiàng)。
//T:nn                    啟用超時(shí):腳本可以運(yùn)行的最大秒數(shù)。默認(rèn)設(shè)置是無(wú)限制。//T 參數(shù)通過(guò)設(shè)置定時(shí)器來(lái)防止腳本執(zhí)行過(guò)度。當(dāng)執(zhí)行時(shí)間超過(guò)指定值時(shí),CScript 用 IActiveScript::InterruptThread 方法中斷腳本引擎,并終止過(guò)程。
//U                       用于 Windows NT 和 Windows 2000,強(qiáng)制命令行以 Unicode 格式輸出。CScript 無(wú)法決定以 Unicode 還是以 ANSI 輸出;默認(rèn)設(shè)置為 ANSI。
//X                       在調(diào)試程序中啟動(dòng)該程序。
//?    

微軟的解釋:

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.)

復(fù)制代碼 代碼如下:

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

“Wscript和Cscript運(yùn)行腳本有哪些區(qū)別”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI