无法使用IHTMLDocument2 [英] Unable to use IHTMLDocument2
问题描述
$wc = New-Object System.Net.WebClient
$DownloadString = $wc.DownloadString("http://www.example.com")
$HTML = New-Object -ComObject "HTMLFile"
$HTML.IHTMLDocument2_write($DownloadString)
服务器脚本运行
Major Minor Build Revision
----- ----- ----- --------
5 1 14409 1005
开发PC
Major Minor Build Revision
----- ----- ----- --------
5 1 15063 502
我的Windows 10开发PC在上面的代码下工作正常.我想在我的Server 2008 R2 x64计算机上运行它.我已将其升级到PowerShell v5.我得到以下信息:
My Windows 10 development PC worked fine with the code above. I want to run this on my Server 2008 R2 x64 machine. I upgraded it to PowerShell v5. I get the following:
方法调用失败,因为[System .__ ComObject]不包含名为'IHTMLDocument2_write'的方法.
Method invocation failed because [System.__ComObject] does not contain a method named 'IHTMLDocument2_write'.
然后再下线...
Unable to find type [mshtml.HTMLDocumentClass].
推荐答案
有帮助的问题:可以不使用InternetExplorer.Application对象?
从我的计算机中复制了Microsoft.mshtml.dll,该计算机可在C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies
中工作到服务器.然后在脚本的开头添加Add-Type -Path "C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\microsoft.mshtml.dll"
.
Copied Microsoft.mshtml.dll from my machine that worked to the server in C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies
. Then added Add-Type -Path "C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\microsoft.mshtml.dll"
at the beginning of my script.
我还注意到(运行脚本时)出现了一些IE安全性框,并且Windows服务器的IE安全性设置可能会受到干扰(因为它比客户端要高得多).也许如果降低我的设置,则无需复制.dll就可以解决此问题.但是,我认为升级到PSv5至关重要(因为甚至连enum
都未被认可).
I also noticed some IE security boxes appear (when running my script) and it's possible the IE security settings of a Windows server would interfere (being it's much higher than a client would be). Perhaps if my settings were lowered, this would be resolved without copying the .dll. However, I think upgrading to PSv5 was crucial (as even enum
wasn't recognized).
这篇关于无法使用IHTMLDocument2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!