Discussion:
JScript (or VBScript) and CoCreateInstance
(too old to reply)
s***@yahoo.com
2003-07-23 16:07:56 UTC
Permalink
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!
Notre Poubelle
2003-07-24 20:19:17 UTC
Permalink
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
2003-07-24 20:45:55 UTC
Permalink
Hi,

[snipped]
Post by Notre Poubelle
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
2003-07-24 22:17:32 UTC
Permalink
Post by Notre Poubelle
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
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 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
Joe Earnest
2003-07-24 22:53:20 UTC
Permalink
Hi Again,
Post by Notre Poubelle
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
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?
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)
2003-07-25 03:54:29 UTC
Permalink
Post by Joe Earnest
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
2003-07-25 15:41:07 UTC
Permalink
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.

Loading...