Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling an already existing instance of IE 1

Status
Not open for further replies.

Elektryon

Technical User
Jul 10, 2004
12
US
I know that it's possible to run an instance of Internet Explorer from within the script itself and be able to control it, but is there a way to control an already existing instance of it?

The closest I've been able to come to this is to use WshShell.AppActivate to give it the focus and WshShell.Sendkeys for control, but that does not allow for using other methods of more direct control as well as the .ReadyState property, which I want to use for a delay loop (far better than a constant delay to wait for the page to load).

Thanks for the help.
 
Hello Elektryon,

To use getobject on internetexplorer.application, it will fail.

The next candidate to take up the control of an existing HTMLDocument instance is to use shell.application windows collection. But it needs to have active desktop.

Suppose you want to take over the instance with url this is how you can do.
Code:
sURL="[URL unfurl="true"]http://www.microsoft.com/"[/URL]
set oie=nothing
set shapp=createobject("shell.application")
on error resume next
for each owin in shapp.windows
    if strcomp(sURL,owin.document.location.href,1)=0 then
        set oie=owin
    end if
next
on error goto 0
set cwin=nothing : set shapp=nothing

if not oie is nothing then
    'here you have got the searched object
    'and can manipulate it, for instance navigate.
    oie.navigte "[URL unfurl="true"]www.google.com"[/URL]
end if
set oie=nothing
regards - tsuji
 
Thank you very much tsuji, it's amazing how neatly that script worked, and also how versatile it is as it looks as though this could work with many other things.

Thanks again,
Elektryon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top