CreateObject 和 Wscript.CreateObject 有什么区别? [英] What is the difference between CreateObject and Wscript.CreateObject?

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

问题描述

有谁知道使用以下选项的原因:

Does anyone know the reasoning behind having the option using:

Wscript.CreateObject("some.object")

CreateObject("some.object")

在 VBScript 中?当我找到使用 Wscript.CreateObject 的文档或示例时,我通常使用 CreateObject 重写,因为它似乎总是有效,然后我可以轻松地在 HTA 中重用代码或 ASP.但我一直想知道为什么存在此功能,如果您在 VBScript 中使用一种或另一种方式,它会产生什么不同.

within VBScript? when I find documentation or examples that use Wscript.CreateObject, I usually rewrite using CreateObject, because it always seems to work, and then I can easily reuse the code within an HTA or ASP. But I've always wondered why this feature existed and if what difference it makes if you use one way or another within VBScript.

推荐答案

当您仅使用一个参数调用它们时,两者之间没有区别.做完全一样的事情.

There's no difference between the two, when you call them with just one argument. The do exactly the same thing.

两者之间的差异仅在您使用两个参数调用时才明显.声明

The difference between the two is only in evidence if you call with two parameters. The statements

Wscript.CreateObject("some.object", "AnotherParam")

CreateObject("some.object", "AnotherParam")

做完全不同的事情:

VBScript CreateObject 函数将第二个参数解释为远程计算机名称,并尝试在该远程计算机上创建命名的 COM 对象;在此示例中,它尝试在名为AnotherParam"的远程计算机上实例化 ProgId 为some.object"的对象实例.WScript CreateObject 方法将第二个参数解释为用于处理来自对象的事件的子例程前缀.这两个 GetObject 函数的关系类似.

The VBScript CreateObject function interprets the second parameter as a remote computer name and tries to create the named COM object on that remote computer; in this example, it tries to instantiate an instance of an object with ProgId of "some.object" on a remote computer named "AnotherParam". The WScript CreateObject method interprets the second parameter as a subroutine prefix to be used in handling events from the object. The two GetObject functions are similarly related.

(改编自 TechNet,比较 VBScript CreateObject 和 GetObject 函数与 WSH"部分.)

(Adapted from TechNet, section "Comparing VBScript CreateObject and GetObject Functions with WSH".)

这篇关于CreateObject 和 Wscript.CreateObject 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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