【问题标题】:Execute a file in VBScript with cscript.exe and not wscript.exe使用 cscript.exe 而不是 wscript.exe 在 VBScript 中执行文件
【发布时间】:2011-07-29 13:20:50
【问题描述】:

我知道如何使用 wscript.exe 执行 exe,如下所示:

Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.Run "c:\myprogram.exe"

但是我不得不用 cscript.exe 运行我的 vbscript,并且不能使用 WScript 对象。 cscript.exe加载后有什么办法可以执行exe吗?

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    wscript.exe 和 cscript.exe 都提供 WScript 对象;所以“Set WshShell = WScript.CreateObject(...)”对于以“w|cscript.exe whatever.vbs”开头的 .vbs 文件是可以的。 VBScript - 语言 - 提供自己的 CreateObject() 函数,因此您可以在所有脚本(.hta、html 也)中使用普通的“Set WshShell = CreateObject(...)”。 WScript COM 对象是另一个对象。您可以在“任何地方”使用它(如果我们忽略安全设置)。简而言之:您的代码在两个主机上都可以工作(或失败)。

    【讨论】:

    • 谢谢!我只是将代码更改为: Set WshShell = CreateObject("WScript.Shell") 然后它工作了,谢谢! :)
    【解决方案2】:
    Set objShell = CreateObject("WScript.Shell")
    objShell.run("cscript d:\Test2.vbs") 
    

    【讨论】:

    • 虽然这可能会解决 OP 的问题,但请提供代码说明
    猜你喜欢
    • 2010-11-30
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    • 1970-01-01
    相关资源
    最近更新 更多