WSCRIPT與CScript區別
視窗中運行,WSCRIPT;命令列中運行,CScrip;
cscript因為把輸出放進了控制台 所以可以對它重新導向 方便程式調用
wscript直接用視窗輸出 適合偵錯工具和編寫小工具 在windows下不用cmd的話cscript的輸出會一閃而過 大多數情況下,列在下表中的選項適用於 WScript.exe 和 CScript.exe。例外情況會加以注釋。
參數 說明
//B 批處理模式;隱藏使用者提示和指令碼錯誤在命令列中的顯示。預設模式是互動模式。
//D 開啟偵錯工具。
//E:engine 用指定的指令碼引擎執行指令碼。
//H:CScript或 //H:Wscript 將 CScript.exe 或 WScript.exe 註冊為運行指令碼的預設應用程式。如果未指定,則將 WScript.exe 假設為預設應用程式。
//I 預設。互動模式;允許顯示使用者提示和指令碼錯誤。與批處理模式相反。
//Job:<JobID> 從 .wsf 檔案運行指定的 JobID。
//logo 預設。顯示標題。與 nologo 相反。
//nologo 防止在運行時顯示執列名。預設設定是 logo。
//S 儲存該使用者的當前命令列選項。
//T:nn 啟用逾時:指令碼可以啟動並執行最大秒數。預設設定是無限制。//T 參數通過設定定時器來防止指令碼執行過度。當執行時間超過指定值時,CScript 用 IActiveScript::InterruptThread 方法中斷指令碼引擎,並終止過程。
//U 用於 Windows NT 和 Windows 2000,強制命令列以 Unicode 格式輸出。CScript 無法決定以 Unicode 還是以 ANSI 輸出;預設設定為 ANSI。
//X 在偵錯工具中啟動該程式。
//?
微軟的解釋:
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.)
複製代碼 代碼如下:
Wscript.Echo "Line 1."
Wscript.Echo "Line 2."
Wscript.Echo "Line 3."
Wscript.Echo "Line 4."