使用CLSID创建COM组件的实例

时间:2018-12-05 20:58:30

标签: powershell

运行脚本时出现以下错误。开始弹出之前,需要经过几个循环。

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

1 个答案:

答案 0 :(得分:1)

如果您在循环中不断创建一个新的Internet Explorer Com对象而在完成时不销毁它,那么您一定会遇到ResourceUnavailable错误。

完成使用对象从内存中清除对象后,将其放入代码(循环)中:

$ie.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($ie) | Out-Null
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()