脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - VBS - Wscript 和 Cscript 运行脚本的区别详解

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

2020-08-13 11:13脚本之家 VBS

WSCRIPT与CScript的主要区别在于WSCRIPT窗口中运行返回对话框,而CScrip在命令行中运行,一般不需要特别注明,程序会提示

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

延伸 · 阅读

精彩推荐
  • VBSVBS数组深入浅出

    VBS数组深入浅出

    VBS数组在应用中没有像其他语句那么广泛,VBS数组存在不少功能上的局限性(如二维数组的定义、赋值),在使用上也没有java等语言那么便捷...

    VBS教程网2962020-08-18
  • VBSVBS文本文件操作实现代码

    VBS文本文件操作实现代码

    这篇文章主要介绍了VBS文本文件操作实现代码,需要的朋友可以参考下...

    VBS代码网8912020-08-12
  • VBS雷客图ASP站长安全助手vbs测试版代码

    雷客图ASP站长安全助手vbs测试版代码

    雷客图ASP站长安全助手是一个基于ASP的帮助站长维护网站安全的程序。这个版本(vbs测试版)主要用于服务器本地运行以查找ASP木马。此版本为测试版,希...

    脚本之家2312020-07-03
  • VBSAdsutil.vbs 在脚本攻击中的妙用[我非我原创]

    Adsutil.vbs 在脚本攻击中的妙用[我非我原创]

    adsutil.vbs是什么?相信用过IIS的网管员不会不知道。这是IIS自带的提供于命令行下管理IIS的一个脚本。位于%SystemDrive%\Inetpub\AdminScripts目录下。...

    VBS教程网2312020-07-07
  • VBS灵活实用VBS入门教程应用篇

    灵活实用VBS入门教程应用篇

    上一篇文章我们了解了VBS编程的一些基础知识,要更深入地学习还要学习选择结构和循环结构。 ...

    VBS教程网5742020-07-01
  • VBSWINDOWS脚本实践:为SAP补丁制作的VBS脚本代码

    WINDOWS脚本实践:为SAP补丁制作的VBS脚本代码

    本文主要分享WINDOWS脚本实践:为SAP补丁制作的VBS脚本代码,有需要的童鞋可以参考下...

    脚本之家3232020-07-06
  • VBSVBS编程教程 (第1篇)

    VBS编程教程 (第1篇)

    VBScript的全称是:Microsoft Visual Basic Script Editon.(微软公司可视化BASIC脚本版). 正如其字面所透露的信息, VBS(VBScript的进一步简写)是基于Visual Basic的脚本语言....

    VBS教程网4812020-07-15
  • VBSVBS教程:正则表达式简介 -正则表达式语法

    VBS教程:正则表达式简介 -正则表达式语法

    正则表达式语法 一个正则表达式就是由普通字符(例如字符 a 到 z)以及特殊字符(称为元字符)组成的文字模式。该模式描述在查找文字主体时待匹配的...

    VBS教程网3302019-11-25