Internet explorer 无法使用InternetExplorer.Application对象?

Internet explorer 无法使用InternetExplorer.Application对象?,internet-explorer,powershell,Internet Explorer,Powershell,我有一个完整的代码文件,可以在PC上完美地工作。我把它带到另一个,它崩溃了。我使用了这个片段,输出是空的,它没有从对象中得到任何东西。但浏览器确实加载了页面 # Create the IE com object "Lauching IE process..." $ie = new-object -com InternetExplorer.Application $ie.visible = $true # Navigate to the login page "Opening $loginPa

我有一个完整的代码文件,可以在PC上完美地工作。我把它带到另一个,它崩溃了。我使用了这个片段,输出是空的,它没有从对象中得到任何东西。但浏览器确实加载了页面

# Create the IE com object 
"Lauching IE process..."
$ie = new-object -com InternetExplorer.Application 
$ie.visible = $true
# Navigate to the login page
"Opening $loginPage"
$ie.navigate($loginPage) 
"Waiting for page to load..."
# Wait for the page to finish loading 
do {sleep 2} until (-not ($ie.Busy)) 
sleep 2
$ie.document.body.innerHTML
我找到了一些IE安全模型的参考资料,以管理员的身份运行,等等,并对其进行了一些修改

如果我以管理员身份运行脚本,它将无法工作 我已经尽可能地禁用了IE安全 从IE 11降级到IE 9 还是不走运

有什么建议吗


谢谢

我不确定$loginPage变量中存储了什么,所以我用www.google.com替换了它,它打开了页面,但没有显示.document.body.html部分

我发现这个论坛讨论了一个与你描述的类似的问题。他们建议将代码改为

$ie = new-object -com internetexplorer.application 
$ie.Visible = $true
$ie.navigate('https://www.google.com')
while($ie.busy){Start-Sleep -Milliseconds 100}
$ie.document.body | select innerhtml
我试过这个,效果很好


参考:

我不确定$loginPage变量中存储了什么,所以我用www.google.com替换了它,它打开了页面,但没有显示.document.body.html部分

我发现这个论坛讨论了一个与你描述的类似的问题。他们建议将代码改为

$ie = new-object -com internetexplorer.application 
$ie.Visible = $true
$ie.navigate('https://www.google.com')
while($ie.busy){Start-Sleep -Milliseconds 100}
$ie.document.body | select innerhtml
我试过这个,效果很好


参考资料:

好的,我最终解决了这个问题。根据这篇文章:

我还注意到

$ie.document | Get-Member
在坏机器上显示COM对象guid,在好机器上显示mshtml。这台好机器确实安装了Office。我抄了

C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\microsoft.mshtml.dll
给坏了的机器。然后在我的脚本顶部我添加了

Add-Type -Path "C:\dll\Microsoft.mshtml.dll"

答对了,脚本现在可以正常工作了

好吧,我最终解决了这个问题。根据这篇文章:

我还注意到

$ie.document | Get-Member
在坏机器上显示COM对象guid,在好机器上显示mshtml。这台好机器确实安装了Office。我抄了

C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\microsoft.mshtml.dll
给坏了的机器。然后在我的脚本顶部我添加了

Add-Type -Path "C:\dll\Microsoft.mshtml.dll"

答对了,脚本现在可以正常工作了

$loginPage在哪里定义?$loginPage在哪里定义?老兄!我真不敢相信这能奏效!非常感谢你!伙计!我真不敢相信这能奏效!非常感谢你!