使用PowerShell在Windows Server的Internet Explorer中运行Javascript [英] Using PowerShell to run Javascript in Internet Explorer on Windows Server

查看:79
本文介绍了使用PowerShell在Windows Server的Internet Explorer中运行Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段PowerShell脚本:

I have this piece of a PowerShell script:

$IE = New-Object -com InternetExplorer.Application
$IE.Navigate($URL)
While ($IE.ReadyState -Ne 4) {Start-Sleep -Milliseconds 100}
$IE.Document.ParentWindow.ExecScript("var JSIEVariable = new XMLSerializer().serializeToString(document);", "javascript")
$Obj = $IE.Document.ParentWindow.GetType().InvokeMember("JSIEVariable", 4096, 
$Null, $IE.Document.parentWindow, $Null)
$HTML = $Obj.ToString()
$IE.Quit()

在Windows 10上运行正常,但在Windows Server 2016的第4、5和6行上,我得到了错误:

On Windows 10 it works fine but on Windows Server 2016 for lines 4, 5 and 6 I get the error:

您不能在空值表达式上调用方法.

You cannot call a method on a null-valued expression.

我敢肯定,这与Windows Server中防止IE运行Javascript的额外安全性有关.必须有某种方法可以使该安全性回拨到与Windows 10相当的水平,以便此脚本可以正常运行,但我不知道如何实现.我已关闭IE增强安全配置,并确保启用了活动脚本.除此之外,我不知道该怎么办.

I'm pretty sure it has something to do with extra security in Windows Server preventing IE from running Javascript. There must be some way to dial back that security to be more on par with Windows 10 so that this script can run properly, but I can't figure out how. I've turned off IE Enhanced Security Configuration and ensured that Active Scripting is enabled. Aside from that I don't know what else to do.

推荐答案

一个同事帮我弄清楚了这一点.它与IE安全性没有任何关系,至少与尚未涉及的内容无关.问题是GAC中缺少"Microsoft.mshtml.dll".全新安装的Windows Server不会提供该功能,但安装Office或Visual Studio之类的功能后会添加它.但是,我敢打赌,大多数运行Windows Server的人并不想为了使它正常工作而这样做.我要做的是将以下文件夹/文件结构从Windows 10 PC复制到服务器,关闭了PowerShell和ISE的所有实例,当我再次打开PowerShell并运行脚本时一切正常.

A coworker helped me figure this out. It doesn't have anything to do with IE security, at least not as far as anything that hasn't already been covered. The problem is 'Microsoft.mshtml.dll' is missing from the GAC. It won't be present on a clean install of Windows Server but installing something like Office or Visual Studio will add it. However, i would bet that most people running a Windows Server wouldn't want to do that just for the sake of getting this working. What I did was copy the following folder/file structure from my Windows 10 PC to my server, closed out all instances of PowerShell and ISE and when I opened PowerShell again and ran the script everything worked.

C:\ Windows \ assembly \ GAC \ Microsoft.mshtmlC:\ Windows \ assembly \ GAC \ Microsoft.mshtml \ 7.0.3300.0__b03f5f7f11d50a3aC:\ Windows \ assembly \ GAC \ Microsoft.mshtml \ 7.0.3300.0__b03f5f7f11d50a3a \ Microsoft.mshtml.dllC:\ Windows \ assembly \ GAC \ Microsoft.mshtml \ 7.0.3300.0__b03f5f7f11d50a3a__AssemblyInfo __.ini

C:\Windows\assembly\GAC\Microsoft.mshtml C:\Windows\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a C:\Windows\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a\Microsoft.mshtml.dll C:\Windows\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a__AssemblyInfo__.ini

这篇关于使用PowerShell在Windows Server的Internet Explorer中运行Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆