How to use ComObjActive in stead of ComObjCreate in com interface for Internet Explorer?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 480
Joined: 12 Apr 2015, 03:53

How to use ComObjActive in stead of ComObjCreate in com interface for Internet Explorer?

27 May 2017, 12:16

Friends, as internet explorer (IE) is active and currently web page http://www.google.com is opened in IE. Now when I refresh the web page then it should show the msgbox- now the webpage is fully loaded after getting the webpage fully loaded. For this I tried to use these codes-

Code: Select all

F1::
webpage = http://www.google .com
ie := ComObjcreate("internetexplorer.application")
ie.navigate(webpage)
while ie.busy
sleep 100 
else
msgbox, now the webpage is fully loaded!!!!!!
Return
The codes are working fine. But there is one problem in these codes, is that- they start a new instance of internet explorer in 'process'. See below screen shot-
Image

Every time when i run these codes it starts new instance of Internet Explorer in background (i.e. in process).

To overcome this problem I tried to use comobjactive in stead of comobjcreate. See these codes-

Code: Select all

F1::
webpage = http://www.google .com
ie := ComObjactive("internetexplorer.application")
ie.navigate(webpage)
while ie.busy
sleep 100 
else
msgbox, now the webpage is fully loaded!!!!!!
Return
But these codes are not working at all. When I run these codes it shows the error operation unavailable. I do not see why this is happening as far as i know this error occurs when the window of internet explorer does not exist. But this is showing this error msg even the internet explorer's window is active. See this screen shot-

Image

PLEASE HELP ME...

THANKS A LOT....
I don't normally code as I don't code normally.
YOU do what YOU want, but happens what HE wants.
YOU do what HE wants, will happen what YOU want.
User avatar
Cuadrix
Posts: 224
Joined: 07 May 2017, 08:26

Re: How to use ComObjActive in stead of ComObjCreate in com interface for Internet Explorer?

27 May 2017, 17:59

The reason it opens a new ie instance/process is because ComObjcreate creates a new instance of Internet Explorer.
If you want to get a message box when the page has loaded in an existing IE window, replace ie := ComObjcreate("internetexplorer.application") with this:

Code: Select all

AppIE(URL)
{
   For ie in ComObjCreate( "Shell.Application" ).Windows
      If InStr(ie.FullName, "iexplore.exe" ) && InStr(ie.LocationURL, URL)
         Return ie
}
You also have to define what "ie" in this case is. To do that, place this below the function AppIE(URL) :

Code: Select all

ie := AppIE(URL)
One more thing. You need to remove else from the code, otherwise you will get an error saying "ELSE with no matching IF"
Your final code should look like this:

Code: Select all

F1::
webpage = http://www.google .com
AppIE(URL)
{
   For ie in ComObjCreate( "Shell.Application" ).Windows
      If InStr(ie.FullName, "iexplore.exe" ) && InStr(ie.LocationURL, URL)
         Return ie
}
ie := AppIE(URL)
ie.navigate(webpage)
while ie.busy
sleep 100 
msgbox, now the webpage is fully loaded!!!!!!
Return
Hope it helps.
----
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How to use ComObjActive in stead of ComObjCreate in com interface for Internet Explorer?

27 May 2017, 18:35

To latch onto an existing IE window use WBGet:
Basic Webpage Controls with JavaScript / COM - Tutorial - Tutorials - AutoHotkey Community
https://autohotkey.com/board/topic/4705 ... -tutorial/
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: 0xDEADC0DE, audante, Bing [Bot], Chunjee, freakkk, Google [Bot], mikeyww, TAC109 and 50 guests