Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JScript (or VBScript) and CoCreateInstance

260 views
Skip to first unread message

spamin...@yahoo.com

unread,
Jul 23, 2003, 12:07:56 PM7/23/03
to
Hello,

Is there a way to create a COM object using only a CLSID
and not a progId? The COM object I wish to create does
not have a progId defined so I must use the CLSID. I was
thinking if I could somehow call CoCreateInstance() this
would achieve what I wanted. I am using either VBScript
or JScript from within IE. I do not want to download a
third party ActiveX control and use a method on this third
party control to call CoCreateInstance(). I would like to
use either a builtin IE control, API, or some COM object
that is guaranteed to be on any client machine running any
version of Windows, to create the object. (Or if there is
some language mechanism in VBScript or JScript that I
don't know about that would be even better).

Thanks in advance!

Alexander Mueller

unread,
Jul 23, 2003, 9:37:55 PM7/23/03
to
on 23.07.03 18:07 spamin...@yahoo.com wrote:

> Hello,
>
> Is there a way to create a COM object using only a CLSID
> and not a progId? The COM object I wish to create does
> not have a progId defined so I must use the CLSID. I was
> thinking if I could somehow call CoCreateInstance() this
> would achieve what I wanted. I am using either VBScript
> or JScript from within IE.

In IE objects are creatable with an <OBJECT> tag + the
CLSID:

<object id="agent_ctrl"
classid="clsid:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F">

for example launches Microsoft Agent Control 2.0.
you can refer to its ID-value as an object-reference in
scripting, for example:

agent_ctrl.Characters.Load("Merlin");


I do not want to download a
> third party ActiveX control and use a method on this third
> party control to call CoCreateInstance(). I would like to
> use either a builtin IE control, API, or some COM object
> that is guaranteed to be on any client machine running any
> version of Windows, to create the object. (Or if there is
> some language mechanism in VBScript or JScript that I
> don't know about that would be even better).
>
> Thanks in advance!

Afaik most COM-Classes have progids, if they're scriptable.
So it's kind of astonishing, that yours has none. But i am not
sure if the progid is really required to make the class
createable.


--
Gruesse,
Alex

Notre Poubelle

unread,
Jul 24, 2003, 4:19:17 PM7/24/03
to
Thanks for the suggestion Alexander. The component I want to create
is the ShellWindows coclass, that I believe ships with IE. Looking at
the SHDocVw (Microsoft Internet Controls) type libary, the
ShellWindows coclass has a CLSID of
9BA05972-F6A8-11CF-A442-00A0C90A8F39, according to OLE/View. I
searched the registry for this CLSID and but I couldn't find this key
(for reasons I don't understand). Having said this, I can still write
VB (not VBScript) code like this:


Dim SWs As New SHDocVw.ShellWindows

and this works fine. Looking at OLE/View, ShellWindows implements the
IShellWindows interface, which is a dispatch interface. I would
assume that this interface would therefore be scriptable. Why is
there not a progId if it is scriptable?

Joe Earnest

unread,
Jul 24, 2003, 4:45:55 PM7/24/03
to
Hi,

[snipped]
"Notre Poubelle" <notre_p...@yahoo.com> wrote in message
news:ae38c758.03072...@posting.google.com...


> Looking at OLE/View, ShellWindows implements the
> IShellWindows interface, which is a dispatch interface. I would
> assume that this interface would therefore be scriptable. Why is
> there not a progId if it is scriptable?

It does sound odd. Don't know if this will help or not, but you haven't
already, you might try Mark Pryor's free TLViewer utility. I find it easier
to get scriptable COM object info through it than through the official MS
stuff.

http://mysite.verizon.net/res1ur2j/tlviewer.htm

Joe Earnest

Alexander Mueller

unread,
Jul 24, 2003, 6:17:32 PM7/24/03
to

I cant't give you an answer. I know too little about COM-backgrounds.
I remember that VB - like VBS/JS - uses a the IDispatch-mechanism, when you
create the object with CreateObject and a different mechanism
(the one that result in early binding, forgot the name) if you "create"
the object with "new" and precise typing.

but practically you should test the tip with the <object>-tag.
it really works for me to return a ShellWindows-Collection.
sample:


<html><head><title>Shell Windows</title>
<script language="vbscript">
sub shw()
for each w in sw
w.quit()
next
end sub
</script></head>
<body bgcolor="#C0C0C0" scroll="no">
<object id="sw" classid="clsid:9BA05972-F6A8-11CF-A442-00A0C90A8F39">
</object>
<button onclick="shw()">close all windows!</button>
</body></html>


--
Gruesse,
Alex

Alexander Mueller

unread,
Jul 24, 2003, 6:24:36 PM7/24/03
to
on 25.07.03 00:17 Alexander Mueller wrote:

> on 24.07.03 22:19 Notre Poubelle wrote:
>> Thanks for the suggestion Alexander. The component I want to create
>> is the ShellWindows coclass, that I believe ships with IE. Looking at
>> the SHDocVw (Microsoft Internet Controls) type libary, the
>> ShellWindows coclass has a CLSID of
>> 9BA05972-F6A8-11CF-A442-00A0C90A8F39, according to OLE/View. I
>> searched the registry for this CLSID and but I couldn't find this key
>> (for reasons I don't understand). Having said this, I can still write
>> VB (not VBScript) code like this:
>>
>>
>> Dim SWs As New SHDocVw.ShellWindows
>>
>> and this works fine. Looking at OLE/View, ShellWindows implements the
>> IShellWindows interface, which is a dispatch interface. I would
>> assume that this interface would therefore be scriptable. Why is
>> there not a progId if it is scriptable?

I think i mixed up the terms "scriptable" and "createable"
afaik ShellWindows is scriptable, but not creatable.
though in msdn they mention a progId "Shell.Windows"
which doesn't exist:

http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_programming/objectmap.asp


--
Gruesse,
Alex

Joe Earnest

unread,
Jul 24, 2003, 6:53:20 PM7/24/03
to
Hi Again,

"Notre Poubelle" <notre_p...@yahoo.com> wrote in message
news:ae38c758.03072...@posting.google.com...

Is this what you're after?

set oShell= createobject("shell.application")
set oShellWindows= oShell.windows
wscript.echo typename(oShellWindows)

If so, you might want to do a Google search, as Michael Harris has posted a
number scripts for getting IE window titles using the object collection.

Joe Earnest

Michael Harris (MVP)

unread,
Jul 24, 2003, 11:54:29 PM7/24/03
to
>
> Is this what you're after?
>
> set oShell= createobject("shell.application")
> set oShellWindows= oShell.windows
> wscript.echo typename(oShellWindows)
>
> If so, you might want to do a Google search, as Michael Harris has
> posted a number scripts for getting IE window titles using the object
> collection.

But the OP said in his first post: "...I am using either VBScript or JScript
from within IE...".

The windows collection is not accessible from within IE as a host. The
Shell.Application itself is marked safe for scripting and can be created,
but most of what it exposes is considered UNsafe for scripting and will
generate an error within IE. Now, use within an HTA is another story...


--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp

Microsoft® Windows®2000 Scripting Guide
http://www.microsoft.com/technet/scriptcenter/scrguide/sagsas_overview.asp

Notre Poubelle

unread,
Jul 25, 2003, 11:41:07 AM7/25/03
to
Thanks to everyone who responded. The solution suggested by
Alexander, where the CLSID is embedded in the object tag in the web
page does work, but with one problem. I get a dialog saying that the
ActiveX control control on the page may be unsafe. The user can
choose whether to allow interaction to continue. (At least that's the
behaviour when I run with the default Medium-Low setting for the Local
Intranet zone).

As I understand by reading the security section of the link Alexander
mentioned in another post, this is by design in a web page. As
Michael also notes the windows collection (and indeed any of the Shell
objects according to the web page link provided by Alexander) are not
marked as safe for scripting and will not run using IE as a host,
unless the user enables the "Initialize and script ActiveX Controls
not marked as safe" option for the security zone in which they are
viewing the page. So, it seems I am out of luck.

0 new messages