VBScript 和 CreateObject 问题 [英] VBScript and CreateObject issue

查看:58
本文介绍了VBScript 和 CreateObject 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我并没有真正尝试过是否与 VBScript 相关,但我有机会通过论坛阅读了很多东西,实际上昨天我帮助某人检查了他的脚本为什么不起作用并为他找到了解决方案.所以我在本地修改了这个脚本,并按照我想要的方式完成了它并且它工作了,但是在另一个人一侧,一个对象无法被初始化.

I'm not really experimented if it is about VBScript but I had the occasion to read many things through forums and actually yesterday I helped someone to checkout why his script wasn't working and found him a solution. So I modified this script locally and did it the way I would and it worked but on that other person side one of the object couldn't be initialized.

有罪的线就像

    Set WshNet = WScript.CreateObject("WScript.Network")

另一个人被告知删除 WScript 的东西,它似乎在提问者方面有效.

Another person told to remove the WScript thing and it seems it works on the question asker side.

我首先认为它可能与我这边使用 Wscript.exe 和那个人那边使用 CScript.exe(我的假设)有关,但我在命令行中检查了它,无论如何它都有效.那么,我想知道和理解的是为什么会发生这种情况?为什么调用 CreateObject 的脚本可以与WScript"一起使用.但在另一个系统上,您需要删除该WScript".让它继续工作?感谢您的时间和答案.;)最好的问候.

I first thought it might be linked with the use of Wscript.exe on my side and CScript.exe on that person side (my hypothesis) but I checked this out in the command-line and it worked anyway. So, what I would like to know and understand is why is this happening ? Why does a script calling for CreateObject works with "WScript." but on another system you need to remove that "WScript." to keep it working ? Thank you for your time and answers. ;) Best regards.

推荐答案

WScript.CreateObject"或WScript.Echo"中的WScript"(对象的名称)是由 c|wscript.exe 脚本提供的主持人.如果您在其他主机(例如 ie 或 mshta)下/中运行 VBScript,则没有此类对象.

The "WScript" in "WScript.CreateObject" or "WScript.Echo" is (the name of an object) provided by the c|wscript.exe scripting host. If you run VBScript under/in other hosts (e.g. ie or mshta), there is no such object.

语言本身有一个(不同的!详细信息请参见文档)CreateObject"函数,可以在所有 VBScripts 主机下/中使用.因此,为了安全起见,请使用简单的CreateObject".

The language itself has a (different!, see the docs for details) "CreateObject" function, that can be used under/in all VBScripts hosts. So use plain "CreateObject" to be on the safe side.

WScript.Network"中的 WScript 是 COM 对象的 ProgId 的一部分,该对象可能已安装(或未安装)在您的计算机上.那些'名字'为WScript"的COM对象与c|wscript.exe提供的WScript对象完全不同.

The WScript in "WScript.Network" is part of the ProgId of a COM object that may be installed on your computer (or not). Those COM objects with a 'first name' of "WScript" are completely different from the WScript object provided by c|wscript.exe.

所以我的第一个假设:某人"执行了 ie 或 mshta 下/中的代码并通过删除WScript"解决了问题.来自WScript.CreateObject",即通过回退到 VBScript 自己的 CreateObject.

So my first assumption: The "someone" executed the code under/in ie or mshta and solved the problem by removing the "WScript." from "WScript.CreateObject", that is by falling back to VBScript's own CreateObject.

这篇关于VBScript 和 CreateObject 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆