Creating an instance of the COM component with CLSID

0

I'm getting the following error when I run a script. It takes a few loops before it starts popping up.

New-Object : Creating an instance of the COM component with CLSID 
{0002DF01-0000-0000-C000-000000000046} from the IClassFactory failed due to the 
following error: 80004005 Unspecified error (Exception from HRESULT: 0x80004005 
(E_FAIL)).
At C:\Users\Script.ps1:210 
char:13
+       $ie = New-Object -Com "InternetExplorer.Application"
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
powershell
asked on Stack Overflow Dec 5, 2018 by user2198320 • edited Dec 5, 2018 by Ansgar Wiechers

1 Answer

1

If you are constantly creating a new Internet Explorer Com object in a loop without destroying it when you are finished with it, you are bound to get the ResourceUnavailable error at some point.

Put this in your code (loop) when you are done using the object to clear it from memory:

$ie.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($ie) | Out-Null
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
answered on Stack Overflow Dec 6, 2018 by Theo • edited Dec 6, 2018 by Theo

User contributions licensed under CC BY-SA 3.0