wb := ComObjCreate("InternetExplorer.Application") - How to close after use

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
flipside555
Posts: 25
Joined: 04 Jan 2019, 03:33

wb := ComObjCreate("InternetExplorer.Application") - How to close after use

Post by flipside555 » 27 May 2022, 02:41

I have a script which uses the code below to create an Internet Explorer object. After the script has executed, the IE objects are still hanging around. What is the correct way to dispose of them within the script?

Code: Select all

wb := ComObjCreate("InternetExplorer.Application")
Thanks.

User avatar
boiler
Posts: 16962
Joined: 21 Dec 2014, 02:44

Re: wb := ComObjCreate("InternetExplorer.Application") - How to close after use

Post by boiler » 27 May 2022, 04:52

Code: Select all

wb.Quit()

This should also work:

Code: Select all

wb := ""

flipside555
Posts: 25
Joined: 04 Jan 2019, 03:33

Re: wb := ComObjCreate("InternetExplorer.Application") - How to close after use

Post by flipside555 » 06 Jun 2022, 06:29

boiler wrote:
27 May 2022, 04:52

Code: Select all

wb.Quit()

This should also work:

Code: Select all

wb := ""
For some reason, neither of these works. The first one throws an error.
image.png
image.png (22.08 KiB) Viewed 914 times

The second one executes but it leaves the IE executable running. If I do

Code: Select all

wb := ""
before

Code: Select all

wb.Quit()
, it no longer throws an error, but the executable still isn't destroyed.
I can't think that statements like the one below would hold a handle to the IE instance and prevent it being destroyed would they?
Attachments
image.png
image.png (15.8 KiB) Viewed 919 times

User avatar
boiler
Posts: 16962
Joined: 21 Dec 2014, 02:44

Re: wb := ComObjCreate("InternetExplorer.Application") - How to close after use

Post by boiler » 06 Jun 2022, 07:33

flipside555 wrote: The second one executes but it leaves the IE executable running. If I do

Code: Select all

wb := ""
before

Code: Select all

wb.Quit()
, it no longer throws an error, but the executable still isn't destroyed.
wb.Quit() can’t do anything at that point because wb is no longer containing the web browser object.
flipside555 wrote: I can't think that statements like the one below would hold a handle to the IE instance and prevent it being destroyed would they?
I don’t know what’s happening to cause your issue. It might be that you’ve assigned something else to wb in the lines of your script that aren’t shown, so wb may no longer be an object that supports the .Quit() method. You might want to check the rest of your script to see if you assign anything else to wb after the initial wb := ComObjCreate("InternetExplorer.Application") including any elements of the main web object. The variable wb cannot be assigned anything else.

flipside555
Posts: 25
Joined: 04 Jan 2019, 03:33

Re: wb := ComObjCreate("InternetExplorer.Application") - How to close after use

Post by flipside555 » 06 Jun 2022, 09:09

boiler wrote:
06 Jun 2022, 07:33
I don’t know what’s happening to cause your issue. It might be that you’ve assigned something else to wb in the lines of your script that aren’t shown, so wb may no longer be an object that supports the .Quit() method. You might want to check the rest of your script to see if you assign anything else to wb after the initial wb := ComObjCreate("InternetExplorer.Application") including any elements of the main web object. The variable wb cannot be assigned anything else.
This seems to be the line causing the problem. Calling wb.quit() before this line is successful. Calling it after fails with the error message. I have to confess I don't really understand what is going on in this line. I wrote the script a few years ago, and I must have copied this part of the code from this site.

Code: Select all

gui,  Add, ActiveX, x0 y0 w1024 h600 vWB,about:<!DOCTYPE html><meta http-equiv="X-UA-Compatible" content="IE=edge">

flipside555
Posts: 25
Joined: 04 Jan 2019, 03:33

Re: wb := ComObjCreate("InternetExplorer.Application") - How to close after use

Post by flipside555 » 06 Jun 2022, 09:17

This is a minimal case.

Code: Select all

wb := ComObjCreate("InternetExplorer.Application")
wb.Navigate( "https://www.microsoft.com/")
;wb.Quit() here works
gui,  Add, ActiveX, x0 y0 w1024 h600 vWB,about:<!DOCTYPE html><meta http-equiv="X-UA-Compatible" content="IE=edge">
wb.Quit() ; this fails

User avatar
boiler
Posts: 16962
Joined: 21 Dec 2014, 02:44

Re: wb := ComObjCreate("InternetExplorer.Application") - How to close after use

Post by boiler » 06 Jun 2022, 12:48

You have assigned the variable WB to be the variable associated with that ActiveX control (that's what vWB does). You shouldn't tie it to that variable. Change the vWB to something else like vWeb.

flipside555
Posts: 25
Joined: 04 Jan 2019, 03:33

Re: wb := ComObjCreate("InternetExplorer.Application") - How to close after use

Post by flipside555 » 06 Jun 2022, 12:53

Yes, thanks. That's what I did. I am manually building an HTML page that I want to display. I didn't fully understand that line and ended up re-using the same variable I'd used earlier when I created the com object. I renamed it vWX and it's working now. Thanks a lot for your help.

Post Reply

Return to “Ask for Help (v1)”