# Killing an Internet Explorer process started by Powershell

**URL:** <https://forums.powershell.org/t/killing-an-internet-explorer-process-started-by-powershell/5966>\
**Category:** PowerShell Help\
**Created:** [March 9, 2016, 10:50pm UTC](https://forums.powershell.org/t/killing-an-internet-explorer-process-started-by-powershell/5966 "2016-03-09T22:50:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![john-quick](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@john-quick](https://forums.powershell.org/u/john-quick)\
**Post date:** [March 9, 2016, 10:50pm UTC](https://forums.powershell.org/t/killing-an-internet-explorer-process-started-by-powershell/5966/1 "2016-03-09T22:50:56Z")

</div>

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" http://www.nu.nl -PassThru
```

Then I want to close this process so I use

```
$process.Kill()
```

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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [March 9, 2016, 11:54pm UTC](https://forums.powershell.org/t/killing-an-internet-explorer-process-started-by-powershell/5966/2 "2016-03-09T23:54:04Z")

</div>

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
$ie.Navigate('http://www.nu.nl')

# then later:

$ie.Quit()
```

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [March 10, 2016, 12:35am UTC](https://forums.powershell.org/t/killing-an-internet-explorer-process-started-by-powershell/5966/3 "2016-03-10T00:35:18Z")

</div>

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” [http://www.nu.nl](http://www.nu.nl)

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

---

<div class="post-metadata">

**Author:** ![john-quick](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@john-quick](https://forums.powershell.org/u/john-quick)\
**Post date:** [March 10, 2016, 1:23am UTC](https://forums.powershell.org/t/killing-an-internet-explorer-process-started-by-powershell/5966/4 "2016-03-10T01:23:33Z")

</div>

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 ([Turk Stream - WebService Login](https://sharepoint.southstream.info/Pic_Announcement_Icons/users))  
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 [http://www.nu.nl](http://www.nu.nl) or even [httpS://www.google.com](httpS://www.google.com) it closes the window as expected. Any idea what can be the issue here?

Richard,

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?

---

<div class="post-metadata">

**Author:** ![john-quick](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@john-quick](https://forums.powershell.org/u/john-quick)\
**Post date:** [March 10, 2016, 1:48am UTC](https://forums.powershell.org/t/killing-an-internet-explorer-process-started-by-powershell/5966/5 "2016-03-10T01:48:19Z")

</div>

Thank you both for pointing me in the right direction.

I use the below and it works perfectly

Start:

```
Start-Process iexplore https://sharepoint.southstream.info/Pic_Announcement_Icons/users
```

Stop

```
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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:42pm UTC](https://forums.powershell.org/t/killing-an-internet-explorer-process-started-by-powershell/5966/6 "2024-05-16T20:42:42Z")

</div>


