About two years back, Notre Poubelle was looking for a way to get ahold
of ShDocVw.ShellWindows via script. Now ignoring the fact that it is
essentially identical to CreateObject("Shell.Application").Windows,
this is an interesting problem because the class id was known, but that
was all.
There was a clever idea by Alexander Mueller, which was tested out,
that maybe it was possible to use IE for this, but it failed because of
the security blanket that IE surrounded the object with. However,
here's a working solution, which extends the original idea. The key
idea is that after having IE create the object, we take it away from IE
so the security restrictions will no longer exist. Even if it wasn't
clear to IE that our app could freely muck with it, it should be clear
to everybody that our VB app/script is free to go about it's own
business on its own time.
Dim ie, Tname, oWins, win, text
Set ie=CreateObject("InternetExplorer.Application")
ie.Navigate2("about:blank")
ie.Document.open
ie.Document.write "<object id=sw classid='clsid:" & _
"9BA05972-F6A8-11CF-A442-00A0C90A8F39'></object>"
ie.Document.close
Set oWins = ie.document.parentWindow.sw 'transfer object
ie.Document.parentWindow.execScript "window.sw=null" 'paranoia
ie.quit 'more of same
msgbox "oWins: " & typename(oWins)
'This loop prints out something on each instance of IE / Explorer
For each win in oWins
Tname = typename(win.document)
if mid(Tname,1,12)="HTMLDocument" Then
text = win.document.title
if text<>"" then text = "Title: " & text & vbCrLF
MsgBox text & "url: " & win.document.location
Else
MsgBox "Folder: " & win.locationURL
End If
Next
This code was adapted from:
http://groups.google.com/group/microsoft.public.scripting.jscript/browse_frm/thread/cb42d8b604de28eb/
The reason I said ShDocVw.ShellWindows was essentially the same as
CreateObject("Shell.Application").Windows was because of hooking event
handlers up. For example, in a VB project, if I do
Dim WithEvents ogSW As SHDocVw.ShellWindows
Set ogSW = New SHDocVw.ShellWindows
then I can receive events of IE/Explorer creations/destruction via:
Private Sub ogSW_WindowRegistered(ByVal lCookie As Long)
and
Private Sub ogSW_WindowRevoked(ByVal lCookie As Long)
but this approach does not work with the other.
Enjoy,
Csaba Gabor from Vienna