VBScript 和 CreateObject 问题
如果是关于 VBScript,我并没有真正进行过实验,但我有机会通过论坛阅读了很多内容,实际上昨天我帮助某人检查了为什么他的脚本不起作用,并为他找到了解决方案。因此,我在本地修改了这个脚本,并按照我的方式进行了操作,它工作了,但在另一方,对象之一无法初始化。
被指控的行就像
Set WshNet = WScript.CreateObject("WScript.Network")
另一个人被告知删除 WScript 的东西,似乎它在提问者方面起作用。
我首先认为这可能与我这边使用 Wscript.exe 和那个人那边使用 CScript.exe 有关(我的假设),但我在命令行中检查了这一点,无论如何它都有效。 那么,我想知道和理解的是为什么会发生这种情况? 为什么调用 CreateObject 的脚本可以与“WScript”一起使用。但在另一个系统上,您需要删除该“WScript”。让它继续工作? 感谢您的时间和答复。 ;) 此致。
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.
The incriminated line is like
Set WshNet = WScript.CreateObject("WScript.Network")
Another person told to remove the WScript thing and it seems it works on the question asker side.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“WScript.CreateObject”或“WScript.Echo”中的“WScript”(对象的名称)由 c|wscript.exe 脚本主机提供。如果您在其他主机(例如 ie 或 mshta)下运行 VBScript,则不存在此类对象。
该语言本身有一个(不同!有关详细信息,请参阅文档)“CreateObject”函数,可以在所有 VBScripts 主机下/中使用。因此,为了安全起见,请使用普通的“CreateObject”。
“WScript.Network”中的 WScript 是可能安装在您的计算机上(或未安装)的 COM 对象的 ProgId 的一部分。那些“名字”为“WScript”的 COM 对象与 c|wscript.exe 提供的 WScript 对象完全不同。
所以我的第一个假设:“某人”在 ie 或 mshta 下/中执行了代码,并通过删除“WScript”解决了问题。来自“WScript.CreateObject”,即回退到 VBScript 自己的 CreateObject。
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.
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.
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.
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.