separate IE instances?

J Correia correiajREMOVECAPS at hotmail.com
Mon Jun 13 11:46:50 EDT 2005


<erinhouston at gmail.com> wrote in message
news:1118671935.537464.150380 at z14g2000cwz.googlegroups.com...
> Sorry about that I had an instance of ie running in the background that
> was version 0  didn't see the problem tell this morining when my
> computer started to not work.  it should be hwnds[1] should be
> hwnds[0].  I woud enumerate them like in the code below.
>
> If you have ie as your default browser you can use a
> shellExecute(0,None,"some url here", None, None, 1)
> To open directley to that page.
>
> Here is a more complete script:
> import win32api, time
> from win32com.client import Dispatch
> a = win32api.ShellExecute(0,None,"iexplore.exe",
> "www.ishpeck.net",None,1)
> b = win32api.ShellExecute(0,None,"iexplore.exe",
> "www.google.com",None,1)
> internetExplorerClassIdentity='{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
> hwnds = Dispatch(internetExplorerClassIdentity)
> # way I showed you before dosn't work verry well if more then one ie is
> open
> #ieObj = hwnds[0]
> #ieObj.Navigate("http://www.google.com/search?hl=en&lr=&q=python")
> time.sleep(30)
> for i in range(hwnds.Count):
> ....if hwnds[i].LocationURL.lower().find("ishpeck") > -1:
> ........ieObj1 = hwnds[i]
> ....if hwnds[i].LocationURL.lower().find("google") > -1:
> ........ieObj2 = hwnds[i]
>
> ieObj1.Navigate("http://www.google.com/search?hl=en&lr=&q=python")
>
ieObj2.Navigate("http://groups-beta.google.com/group/comp.lang.python/browse_thr
ead/thread/ba1395566452dba6/343672a01d5b2cdc?hl=en#343672a01d5b2cdc")

The thing to note is that hwnds brings back a list of all Internet Explorer
 objects running on your machine.  This *includes* things that might
not be obvious at first, like a simple Windows Explorer window
(or windows) you have running (since it uses IE in the background).
Printing hwnds.LocationName and hwnds.LocationURL in a loop
will show you exactly what processes are using IE at the time you run it.
Given that the returned list will vary each time you run your program
you'll definitely have to iterate through each hwnds item and check
if it is the browser session you want as shown in the above code.

JC





More information about the Python-list mailing list