Semjon katatsc 2007-03-30 13:23:08
I looked at the MS WebBrowser object and there are some nice events, but I
don’t understand how to use them and there is absolutely no information on
the ENTIRE internet incl. the MS site on how to use them in VBScript or
Jscript. There are just some VBA examples. You can never find any vbscripts
on the MS site, no matter what you are searching for!
Ok, so I want to connect to an existing IE session and then listen for
events like DownloadBegin. So I write:
set objShell = CreateObject(“Shell.Application”)
set objShellWindows = objShell.Windows
Set objIE = objShellWindows.Item(0)
WScript.ConnectObject objIE , “objIE _”
But VBScript says “object is not connected”. What the h***? If only MS
provided at least some examples! What good are technologies if nobody knows
how to use them?
I can use the methods and properties of WebBrowser and the Internetexplorer
activex objects, like obj.Navigate, obj.Addressbar etc., they work, but not
the events. Please heeelp!
Michael harris 2007-03-30 17:40:53
Unfortunately, IE is not an object that will work with the ConnectObject
The only way to sink IE host related events (as opposed to DHTML DOM events
of a displayed page) from an external js/vbs client is to create the object
instance originally via the WScript.CreateObject method (2nd arg).
Microsoft MVP Scripting
Mr_unreliable 2007-03-31 05:52:45
I assume you tried connecting to the events of the “parentwindow”
of the doc object and that didn’t work either.
There is one other avenue to try, especially if this is all
running on _your_ system, and you are not some sysadmin attempting
to get this to work on thousands of clients.
If you read ms’s support article “How to connect to a running
instance of Internet Explorer”:
You will find a vb-oriented rendition of the same thing you are
doing with shell.applicaton (shdocvw.dll). At the bottom of
the page, it further says that if this doesn’t work for you,
then there is another possibility, and that is adding IE to
the “Running Object Table” (or, “ROT” for short), using a
“browser helper object”.
Further, if you look at ms’s support article “SAMPLE: IEHelper-
Attaching to Internet Explorer 4.0 by Using a Browser Helper
Object”, found here:
you will find such a helper object, i.e., the IEHelper.exe
download. Once you download and install the helper object,
(or write one yourself) then you can get IE to register itself
in the ROT.
O.K., now back to scripting. You can attach yourself to an
object in the ROT by using the “GetObject” method, (rather
than CreateObject). And finally, you may be able to sink
events using the wsh/vbs “ConnectObject” method.
Caveat Emptor. I only suggest this as a possibility. I have
not attempted to use it myself.
You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
Mr_unreliable 2007-03-31 05:52:50
A vb example of what I am talking about may be found here:
If effect, Garcia Francois is getting an IE window from
shell.application, then connecting to that IE window’s
events using the mshtml.tlb (the HTMLWindow2 class).
One might assert that if one can do this with vb, then
one ought to be able to do it in vbs also.
Mr_unreliable 2007-03-31 05:52:52
Er, sorry about the confusion, the above reference
is not what I was talking about in the original
posting (i.e., BHO’s).
It was the result of searching on different keywords.
Anyway, it is a possible way to get at the IE events.
Even if it is not do-able in “pure” script, one could
write an actX object using the msHTML.tlb, and provide
event interfaces back to script.
Semjon katatsc 2007-03-31 22:03:07
Thanks, but this IEHelper is not compiled, and I am not so much into
compiling. Somebody knows where one could get a compiled dll?
You can actually connect to the WebBrowser ActiveX object and then do all
kinds of malicious things that crash Windows Explorer, because the object is
not intended for these purposes:
set objShell2 = WScript.CreateObject(“Shell.Explorer.2″)
Passing arguments to this object will inevitably make Windows Explorer
unstable and eventually crash it, but it’s fun 🙂
And yes, after searching for hours, I eventually found an MS site that
stated that connecting to a running instance of IE using wscript.getobject
/connectobject is impossible. However, the event listening functions are
flawed anyway. Tried the following:
Set objIE = WScript.CreateObject(“InternetExplorer.Application”,”objIE_”)
Sub objIE_FileDownload(ActiveDocument, Cancel)
WScript.Echo “objIE_FileDownload”, FALSE, true
Sub objIE_NavigateComplete2(ByVal pDisp, URL)
WScript.Echo “objIE_NavigateComplete2”, URL
WScript.Echo “objIE_DownloadBegin”, URL
WScript.Echo “objIE_DownloadComplete”, URL
Sometimes the events fire, sometimes they don’t, sometimes they fire at a
totally wrong time, nothing works properly. Back to the designer table, MS
programmers! Fix the bugs! And provide some VBScript examples, goddamnit, I