Powershell 使用CLSID创建COM组件的实例

Powershell 使用CLSID创建COM组件的实例,powershell,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: 0x8

我运行脚本时出现以下错误。在它开始弹出之前需要进行一些循环

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 新对象:使用CLSID创建COM组件的实例 由于以下原因,来自IClassFactory的{0002DF01-0000-0000-C000-0000000000 46}失败: 以下错误:80004005未指定错误(HRESULT异常:0x80004005 (E_FAIL))。 在C:\Users\Script.ps1:210 字符:13 +$ie=新对象-Com“InternetExplorer.Application” + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +CategoryInfo:ResourceUnavailable:(:)[New Object],COMException +FullyQualifiedErrorId:NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
如果在循环中不断创建一个新的Internet Explorer Com对象,但在使用完毕后却没有将其销毁,那么在某个时候肯定会出现
ResourceUnavailable
错误

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

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

如果在循环中不断创建一个新的Internet Explorer Com对象,但在使用完毕后却没有将其销毁,那么在某个时候肯定会出现
ResourceUnavailable
错误

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

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