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.

How to Distinguish between IE window and a Windows Explorer window

Keywords:   IE window and a Windows Explorer window

; This code will distinguish between an
; IE window and a Windows Explorer window. Once you know you have an IE window, you
; can then use OLE "drill down" to get to the document object
; and do what you need to do from there.
;


objShell = CreateObject("Shell.Application")
objInstances = objShell.windows
objWin = 0
If objInstances.Count > 0 ; make sure we have instances open.
    ForEach objWin In objInstances
       sName = StrLower(objWin.FullName)
      ;Pause(0,sName)
      If StrIndex( sName, 'explorer.exe', 1, @FWDSCAN ) != 0 ; windows explorer.
         ret = AskYesNo( "Found instance of Windows Explorer ":objWin.LocationURL, "Is this what you were looking for?" )
         If ret
            objInstances = 0
            objShell = 0
            Break
         EndIf
      EndIf
      If StrIndex( sName, 'iexplore.exe', 1, @FWDSCAN ) != 0 ; internet explorer
         ret = AskYesNo( "Found instance of InternetExplorer ":objWin.LocationURL, "Is this what you were looking for?" )
         If ret
            objInstances = 0
            objShell = 0
            Break
         EndIf
      EndIf
    Next
EndIf
If objWin == 0
   Pause('Notice', 'Unable to locate any running instances')
EndIf


Alternative ( winxp and older)

; This code will distinguish between an
; IE window and a Windows Explorer window. The logic is that
; if the location url does not begins with "file:\\", then
; it is a IE window. Once you know you have an IE window, you
; can then use OLE "drill down" to get to the document object
; and do what you need to do from there.
;


;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
   If StrIndexNC(lu, "file://", 1, @FWDSCAN) != 0 ;this would be a IE window
      Message("Found IE Window",lu)
      doc = windowobject.document
   EndIf
Next

Article ID:   W15648
File Created: 2011:07:15:09:33:10
Last Updated: 2011:07:15:09:33:10