Killing an Internet Explorer process started by Powershell

This topic contains 4 replies, has 3 voices, and was last updated by  John Quick 2 years, 3 months ago.

  • Author
  • #36359

    John Quick

    Dear All,

    I am using the following code to start an IE process and navigate to a website.

    $process = Start-Process "C:\Program Files (x86)\Internet Explorer\iexplore.exe" -PassThru

    Then I want to close this process so I use


    This works beautifully ONLY when one Internet Explorer window is open. If there is already an Internet Explorer window open it will throw the following error

    Exception calling "Kill" with "0" argument(s): "Cannot process request because the process has exited."
    At line:2 char:1
    + $process.Kill()
    + ~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : InvalidOperationException

    How can I close only the Internet Explorer window that was opened from the Powershell session?

  • #36360

    Dave Wyatt

    Hmm.... my suspicion is that IE wants to have a single process, so when it starts up, it looks for another running instance. If it finds one, it tells that instance to open the webpage you asked for (probably via DDE or some such mechanism) and then closes the new process. That would match what you've observed.

    You might be able to work around this by using the COM objects instead of Start-Process:

    $ie = New-Object -ComObject InternetExplorer.Application
    $ie.Visible = $true
    # then later:
  • #36361

    Richard Siddaway

    Another alternative is to capture the IE processes BEFORE you programmatically open IE.
    $procs = Get-Process iexplore | select -ExpandProperty Id
    Start-Process "C:\Program Files (x86)\Internet Explorer\iexplore.exe"

    Get-Process iexplore | where ID -notin $procs | Stop-Process

    This obviously breaks down if you open other IE processes AFTER your start-process. In that case isolate the processes belonging to your IE instance of interest so you can kill them

  • #36362

    John Quick

    Hi Dave,

    Thank you for your suggestion. This works good but....
    The actual URL that I need to use is an internal sharepoint page.
    Whenever I set that URL (
    To start Internet Explorer with it will load IE with that page. However when I use $ie.quit() it shows the following error

    The interface is unknown. (Exception from HRESULT: 0x800706B5)
    At line:1 char:1
    + $ie.quit()
    + ~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [], COMException
        + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

    When I change the URL back to or even it closes the window as expected. Any idea what can be the issue here?


    Thanks for the help. When I use your code IE will restore itself automatically because it thinks it crashed...
    Any idea how to prevent that?

  • #36375

    John Quick

    Thank you both for pointing me in the right direction.

    I use the below and it works perfectly


    Start-Process iexplore


    Get-Process iexplore | Foreach-Object { $_.CloseMainWindow() | Out-Null } | stop-process –force

    This opens the IE window and navigates to the site. And closes it when with the Stop code part.

You must be logged in to reply to this topic.