WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with MSIE
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Getting an OLE document handle for an open MSIE window

This code allows attaching to an existing MSIE window. It has to be run at least once with an Admin account to initialize a registry key to allow WinBatch access to the Shell Windows object. After that anyone can use it.
objShell = CreateObject("Shell.Application")
objInstances = objShell.windows
objIE = 0
If objInstances.Count > 0 ; make sure we have instances open.
    ForEach objIE In objInstances
       sName = StrLower(objIE.FullName)
       If StrIndex( sName, 'iexplore.exe', 1, @FWDSCAN ) != 0 ; internet explorer not windows explorer.
        ret = AskYesNo( "Found instance of Internet Explorer ":objIE.LocationURL, "Would you like to view html?" )
        If ret
           objInstances = 0
           objShell = 0
           Break
        EndIf
      EndIf
    Next
EndIf
If objIE == 0
   Pause('Notice', 'Unable to locate any running instances of InternetExplorer')
EndIf

objDoc = objIE.Document
objMainhtml = objDoc.GetElementsbyTagname("HTML").item(0)
Pause('Webpage data', objMainhtml.innerhtml)
objMainhtml = 0
objDoc = 0
objIE = 0


Alternative way (Winxp and older)

;Getting a OLE document handle for an open MSIE window


;Check to see if ClassID installed
myShellWindowsClsid="{9BA05972-F6A8-11CF-A442-00A0C90A8F39}" ;ShellWindows
myShellWindowsKey="AAA.TEST\CLSID"
If RegExistValue(@REGCLASSES,myShellWindowsKey) == @FALSE
   RegSetValue(@REGCLASSES,myShellWindowsKey,myShellWindowsClsid)
   If RegExistValue(@REGCLASSES,myShellWindowsKey) == @FALSE
      Message("CLSID Not installed.","Need Admin access")
      Exit
   EndIf
EndIf

SWs=ObjectAccess("AAA.TEST",1)
count=Sws.count
Message("Count",count)

For xx=0 To count-1
   windowobject=Sws.Item(xx)
   lu = windowobject.LocationURL
   Message("Debug", windowobject.HWND)
;   If StrIndexNC(lu, "file://", 1, @FWDSCAN) != 0 ;this would be a IE window
      Message("Found IE Window",lu)
      Message("Debug", StrCat(windowobject.name, @CRLF, windowobject.fullname))  ; <----- this seems to be more clear
      doc = windowobject.document
;   EndIf
Next


Article ID:   W16120
File Created: 2012:01:25:12:24:00
Last Updated: 2012:01:25:12:24:00