Two instances of Windows Explorer (other example)

Another example which creates two Microsoft Internet Explorer instances.

import win32process, win32com.client, time 
from win32com.client import gencache
ie_tlb = gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)

def createNewIEProcess():
  """Create new IE process and return WebBrowser2 IDisp to it.
     a work-around for win32com.client.Dispatch("InternetExplorer.App.."),
     which will NOT create a new process
     @return new WebBrowser2 instance
  """
  si = win32process.STARTUPINFO()
  dmy, dmy, newIEprocId, dmy = win32process.CreateProcess(r"C:\Program Files\Internet Explorer\iexplore.exe", None, None, None, 0, 0, None, None, si )
  time.sleep(1.0)
  for idx in range(10):
    for shellWnd in ie_tlb.ShellWindows():
      dmy, processId = win32process.GetWindowThreadProcessId(shellWnd.HWND)
      if processId == newIEprocId:
        return shellWnd

ie1 = createNewIEProcess()
ie1.Top, ie1.Left, ie1.Height, ie1.Width = 0, 0, 50, 50

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.