Closing an IE instance created by WScript.CreateObject


Without calling a powershell command or using com wrapper you may want filter processes by its command line. An iexplorer.exe process which created from dcom launch has a commandline like -Embedding. A sample query about what I meant.

Select * from Win32_Process Where Name = 'iexplore.exe' And CommandLine Like '%-Embedding'

Yes I heard you, this will returns all embedded instances so it may not be useful if there are multiple instances.

An IE object instance has a property that returns mainwindowhandle : HWND.

What can be done to terminate more reliable using HWND :

Running a command from Powershell:

Set WshShell = WScript.CreateObject("WScript.Shell")
strCommand = "powershell -Command ""Get-Process | Where-Object {$_.MainWindowHandle -eq "& IE.Hwnd &"} | kill"""
WshShell.Run strCommand, vbHide, True

Using / writing a component that wraps Windows APIs something like that (32 bit only):

Set obj = CreateObject("APIWrapperCOM.APIWrapper")
    obj.KillWindow IE.Hwnd

Hope it helps.

Author by


Updated on June 04, 2022


  • fredy
    fredy 7 months

    I'm looking for a way to retrieve the process ID from an object that was created by running:

    Set ie = WScript.CreateObject("InternetExplorer.Application", "ie_")

    My problem is that sometimes I see that the iexplorer process remains open and isn't closed after running:


    I found some workarounds, like looking for the newest iexplorer process or looking at the process name, but this isn't good for me since I have several Internet Explorer instances opened in parallel by different processes and it might be on the same time.

    This is not good:

    Set colProcessList = objWMIService.ExecQuery _ 
    ("Select * from Win32_Process Where " _ 
    & "Name = '"& sProcessName & "'") 

    I saw this solution that might work, but I don't know how to implement it for Internet Explorer.