...

GetObject Function vs. GetObject Method

codegoboom
04-19-2005, 06:21 AM
Syntax is just about identical:

JScript Function:
GetObject([pathname] [, class])
WSH Method:
WScript.GetObject(strPathname [,strProgID], [strPrefix])
The first two parameters for each are described as being the same...

I'd like to use the third parameter of GetObject to hook events, but can't, because 'WScript.GetObject' fails:

try
{
var jsComponent = GetObject("script:c:\\test.wsc");
WScript.Echo(typeof jsComponent); // -> object

var wsComponent = WScript.GetObject("script:c:\\test.wsc"); // -> throws error
WScript.Echo(typeof wsComponent);
}
catch(e)
{
WScript.Echo("Hello Failure!"); // -> no real error message available...
}
Whether or not the "script:" moniker is used, the WSH method fails. (The JS function returns "unknown" without the moniker...)
Is it just me? :confused:

codegoboom
04-19-2005, 07:20 AM
Looking back, it does show a message without the moniker:

"Class doesn't support Automation"

Strange...

- isn't automation the whole purpose of script components?
- isn't getting an object from a file the main purpose of GetObject?

Maybe it's just me. :rolleyes:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum