简体   繁体   English

与Server 2008 R2上的Internet Explorer ComObject交互时出现问题

[英]Issue interacting with Internet Explorer ComObject on Server 2008 R2

Ok, so I have written a pretty intense PowerShell script that installs and configures SharePoint 2007 and SQL 2008. That is what it is, please don't judge me. 好的,所以我写了一个非常强大的PowerShell脚本,用于安装和配置SharePoint 2007和SQL2008。这就是事实,请不要判断我。 After finishing all of that up, because the script is supposed to be user friendly, I developed a web form to gather inputs and display task progress. 完成所有这些步骤后,由于该脚本应该是用户友好的,所以我开发了一个Web表单来收集输入并显示任务进度。 Stupidly, I wrote all the code for the web form on Windows 8.1 without even testing the basic functions on Server 2008 R2 where the script will be executed. 愚蠢的是,我在Windows 8.1上编写了Web表单的所有代码,甚至没有测试将在其中执行脚本的Server 2008 R2的基本功能。 When I took the code over to the server, it malfunctioned pretty much immediately. 当我将代码移交给服务器时,它立即立即发生故障。 When I then tested it on Windows 7, it worked fine. 当我在Windows 7上对其进行测试时,它运行良好。

Here is the behavior on Windows 8.1 (w/ IE 11) and Windows 7 (w/ IE 9): 这是Windows 8.1(带有IE 11)和Windows 7(带有IE 9)的行为:

>$ie = New-Object -ComObject InternetExplorer.Application
>$ie.Navigate('about:blank')
>$ie.visible = $true #Internet explorer is now displayed with a blank page
>$ie.document


Script                            : System.__ComObject
all                               : System.__ComObject
body                              : System.__ComObject
activeElement                     : System.__ComObject
images                            : System.__ComObject
applets                           : System.__ComObject
links                             : System.__ComObject
forms                             : System.__ComObject
anchors                           : System.__ComObject
title                             :
scripts                           : System.__ComObject
designMode                        : Inherit
selection                         : System.__ComObject
readyState                        : complete

The list goes on for a while.... 清单持续了一段时间。

Now when I run the same code on Server 2008 R2: 现在,当我在Server 2008 R2上运行相同的代码时:

>$ie = New-Object -ComObject InternetExplorer.Application
>$ie.Navigate('about:blank')
>$ie.visible = $true #Internet explorer is now displayed with a blank page
>$ie.document
System.__ComObject

This is a little bit of a problem as the script pretty heavily relies on writing to and reading from the IE Document object and none of the classes I need are available. 这是一个小问题,因为脚本在很大程度上依赖于IE文档对象的写入和读取,并且我需要的任何类都不可用。 Rather no classes are available, even the ones I don't need. 而是没有可用的类,甚至是我不需要的类。

So is there any way to access the document object on Server 2008 R2? 那么,有什么方法可以访问Server 2008 R2上的文档对象? I have gone through everything that I can think of with the security zone settings (although I may have missed something there), and I have disabled the enhanced security configuration and the IE protected mode. 我已经遍历了安全区域设置中可以想到的所有内容(尽管我可能在此遗漏了一些内容),并且禁用了增强的安全性配置和IE保护模式。 Nothing I have done seems to give me access to the document. 我所做的一切似乎都没有使我可以访问该文档。 Any advice? 有什么建议吗?

One thing that may allow you to still have an HTML but not use if in PowerShell is write an HTA, and export all of the required values from the .hta to a .csv file, and then import those values from the .csv to your Windows PowerShell prompt. 如果在PowerShell中编写HTA,然后将所有必需的值从.hta导出到.csv文件,然后将这些值从.csv导入到您的主机中,则可能仍然允许您使用HTML,但仍然无法使用HTML。 Windows PowerShell提示。 Not the cleanest solution by any means, but it's much easier than XAML / WPF, and is available on more platforms. 无论如何,这都不是最干净的解决方案,但是它比XAML / WPF容易得多,并且可以在更多平台上使用。 The only draw back may be that I don't know if Windows Server supports HTA. 唯一的缺点可能是我不知道Windows Server是否支持HTA。 If it doesn't, a simple workaround might be to run the parameter export piece on a client computer, with the actual installation on the server. 如果不是这样,一个简单的解决方法可能是在客户端计算机上运行参数导出程序,并在服务器上进行实际安装。

Another route might be using the PowerShell script to run the commands against the server, while running the front-end on a client computer. 另一种方法是在客户端计算机上运行前端时,使用PowerShell脚本对服务器运行命令。 I know that Invoke-Command will let you run against the server, but simultaneously grant you the ability to use IE. 我知道Invoke-Command可以让您在服务器上运行,但同时可以授予您使用IE的能力。

Sorry I can't give more advice, but I've never tried doing this on Windows Server before. 抱歉,我无法提供更多建议,但是我之前从未尝试过在Windows Server上进行此操作。

通过使用gacutil.exe将Windows 8.1计算机上的Microsoft.mshtml.dll程序集部署到Server 2008 R2计算机上的GAC并重新启动PowerShell实例来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM