Wscript 和 Cscript 运行脚本的区别详解

所属分类: 脚本专栏 / vbs 阅读数: 1990
收藏 0 赞 0 分享

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

更多精彩内容其他人还在看

提权vbs代码

用了提升用户权限的脚本代码,学习vbs的朋友可以参考下。
收藏 0 赞 0 分享

利用VBS发送短信的实现代码(通过飞信)

无意中看到百度 VBS 贴吧里一个标题为《无私的奉献出我的用飞信免费发短信接口》的帖子。
收藏 0 赞 0 分享

用VBS实现一个小键盘动作CTRL+V粘贴操作与思路分析

我想实现当有跳出窗口"请输入"时的1.8秒后就发送一次 CTRL + V,把本来已经复制到剪切版中的文字自动粘贴过去呢
收藏 0 赞 0 分享

VBS 偏移量解密工具[算法解密]

请将通过偏移量加密过的 VBS 文件拖放到本脚本上即可[请逐个解密
收藏 0 赞 0 分享

自动复制U盘文件的VBS脚本

运行该脚本后,文件会先拷贝到system32目录中然后运行,监控移动存储设备的插入,如果有U盘插入,会将你感兴趣的文件拷贝到电脑相应目录中。
收藏 0 赞 0 分享

vbs 自动复制U盘的内容

运行后当把U盘插入电脑后能够自动把U盘里的PPT偷拷下来。下面用记事本就能实现的批处理或vbs。
收藏 0 赞 0 分享

用vbs实现的利用ADSL拨号变ip刷投票的代码

朋友让我帮刷投票,我看了看,那个投票系统只是限制ip,考虑的不是很全面,可以刷。
收藏 0 赞 0 分享

VBS 断网后自动关机30秒后

只要运行它后,一旦网线被拔掉的话,马上就进入自动关机倒计时,“-t 30”是倒计时的时间,你可以自己调整。
收藏 0 赞 0 分享

写个设置命令的VBS脚本代码

安装成功后,可通过在程序、文件或文件夹上点右键->发送到->系统命令来设置一个命令,然后在运行中就可以输入该命令打开文件了。
收藏 0 赞 0 分享

屏蔽端口的vbs脚本

有时候服务器为了安全只允许访问的端口加到TCP/IP筛选里面,其它的端口将无法访问。这里的代码就是为了这样的功能实现。
收藏 0 赞 0 分享
查看更多