FOUND! how to attach to running instances of Internet Explorer

Discussion in 'Python' started by gcash, Aug 2, 2003.

  1. gcash

    gcash Guest

    Most folks know you can start up an instance of Internet Explorer by
    saying "x=win32com.client.Dispatch('InternetExplorer.Application.1')"
    and you get a WIN32 object with a "Document" object that has arrays of
    "Link"/"Form"/"Frame" subobjects, and methods like "Navigate" where
    you can force the IE instance to browse to a new URL.

    What folks would like to do is to connect to an already running
    version of explorer, and this isn't so obvious.

    The MS KB article you usually find is 176792 which mentions using
    SHDocVw.ShellWindows to iterate through the instances. However Mark
    Hammond sayes this is a "vtable interface" (whatever that is) and "not
    supported by python" in
    http://groups.google.com/groups?hl=...safe=off&selm=

    HA! well, I happened to discover you can do:

    import win32com.client
    # look in the makepy output for IE for the "CLSIDToClassMap"
    # dictionary, and find the entry for "ShellWindows"
    clsid='{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
    ShellWindows=win32com.client.Dispatch(clsid)
    for i in range(ShellWindows.Count):
    print i
    # this is the titlebar value
    print ShellWindows.LocationName
    # this is the current URL
    print ShellWindows.LocationURL
    print

    and the object returned by ShellWindows[n] is the exact same as the
    one returned by Dispatch('InternetExplorer.Application.1')

    I'm posting this here for future generations of Googlers.

    So I'm running Win2K Pro... and I'm curious about what versions this
    works under. I'm pretty sure you have to have IE 5.0 or newer, but
    could folks try this code on 95/98 and tell me (gcash-at-cfl.rr.com)
    if it works??

    Also, I haven't been able to determine if there's a better name of the
    form 'InternetExplorer.Application.1' instead of using the horrid
    class-id. How do you do that? The makepy output for explorer doesn't
    list one.

    Thanks to Mark Hammond for win32all, it is a true work of art, and is
    teaching an old UNIX hack lots of Windows stuff.

    -gc

    --
    I've never tried emacs because I already _have_ an OS on this peecee.
    -- (Mike Andrews)
    gcash, Aug 2, 2003
    #1
    1. Advertising

  2. gcash ....

    Your win32 script for connecting to open IE instances
    works fine for me using ....

    Win98_SE
    Python 2.2.1

    Displays info for open IE instances
    for both local and remote pages ....

    --
    Cousin Stanley
    Human Being
    Phoenix, Arizona
    Cousin Stanley, Aug 2, 2003
    #2
    1. Advertising

  3. gcash

    gcash Guest

    "Cousin Stanley" <> writes:

    > Your win32 script for connecting to open IE instances
    > works fine for me using ....
    >
    > Win98_SE
    > Python 2.2.1


    Awesome! That gives me hope it isn't some one-off WIN2K thing.
    Cool! Thanks.

    -gc

    --
    I've never tried emacs because I already _have_ an OS on this peecee.
    -- (Mike Andrews)
    gcash, Aug 2, 2003
    #3
  4. > Also, I haven't been able to determine if there's a better name of the
    > form 'InternetExplorer.Application.1' instead of using the horrid
    > class-id. How do you do that? The makepy output for explorer doesn't
    > list one.


    The relevant MSDN page[1] lists the ProgID as 'Shell.Windows' or
    'ShellWindows._NewEnum'; however when trying to dispatch with either as the
    class string fails. Also, searching the registry reveals nothing for the
    CLSID.

    [1] http://tinyurl.com/ix1z , i.e.
    http://msdn.microsoft.com/library/d...basics/shell_basics_programming/objectmap.asp
    Jordan Tucker, Aug 3, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?T3NjYXIgRg==?=

    Multiple instances of Internet Explorer.

    =?Utf-8?B?T3NjYXIgRg==?=, Nov 10, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    449
    =?Utf-8?B?T3NjYXIgRg==?=
    Nov 17, 2004
  2. cmay
    Replies:
    0
    Views:
    1,114
  3. Replies:
    0
    Views:
    639
  4. Warren Tang
    Replies:
    1
    Views:
    533
    Warren Tang
    Sep 17, 2008
  5. Ed Hauptman
    Replies:
    7
    Views:
    993
    Ed Hauptman
    Aug 7, 2009
Loading...

Share This Page