Internet explorer 损坏的IE对象(带有Powershell的IE自动化)
我想使用Powershell在web控制台上自动配置accesspoint 我是在Win8/IE10上开发的,在测试代码时一切正常。 不幸的是,我在开发/测试之后收到了“生产系统”。 现在,该代码应该可以在Windows Server 2012 R2/IE11上运行 这是我连接和登录accesspoint的代码(简化): 出于调试原因,我通常会显示窗口(注释1)。 在第一次写入主机时,会显示正确的位置(“登录”)。 在第二个写入主机上,显示错误的位置(“关于:空白”)。 在IE窗口中,您可以看到正确的位置/选项卡名(“AP”)。 IE对象似乎变得不可用,其他属性(如$IE.Document.*)则不起作用。我得手动关窗 我有两个变通办法:Internet explorer 损坏的IE对象(带有Powershell的IE自动化),internet-explorer,powershell,automation,com-object,Internet Explorer,Powershell,Automation,Com Object,我想使用Powershell在web控制台上自动配置accesspoint 我是在Win8/IE10上开发的,在测试代码时一切正常。 不幸的是,我在开发/测试之后收到了“生产系统”。 现在,该代码应该可以在Windows Server 2012 R2/IE11上运行 这是我连接和登录accesspoint的代码(简化): 出于调试原因,我通常会显示窗口(注释1)。 在第一次写入主机时,会显示正确的位置(“登录”)。 在第二个写入主机上,显示错误的位置(“关于:空白”)。 在IE窗口中,您可以看到
kvo我在将脚本部署到运行在IE11上的windows server 2012时遇到了这个问题 原因是失去了Powershell创建的IE对象的处理程序 我使用了在中编写的以下代码段来解决此问题
function ConnectIExplorer() {
param($HWND)
$objShellApp = New-Object -ComObject Shell.Application
try {
$EA = $ErrorActionPreference; $ErrorActionPreference = 'Stop'
$objNewIE = $objShellApp.Windows() | ?{$_.HWND -eq $HWND}
$objNewIE.Visible = $true
} catch {
#it may happen, that the Shell.Application does not find the window in a timely-manner, therefore quick-sleep and try again
Write-Host "Waiting for page to be loaded ..."
Start-Sleep -Milliseconds 500
try {
$objNewIE = $objShellApp.Windows() | ?{$_.HWND -eq $HWND}
$objNewIE.Visible = $true
} catch {
Write-Host "Could not retreive the -com Object InternetExplorer. Aborting." -ForegroundColor Red
$objNewIE = $null
}
} finally {
$ErrorActionPreference = $EA
$objShellApp = $null
}
return $objNewIE
}
$HWND = ($objIE = New-Object -ComObject InternetExplorer.Application).HWND
$objIE.Navigate("https://www.google.com")
$objIE = ConnectIExplorer -HWND $HWND
function ConnectIExplorer() {
param($HWND)
$objShellApp = New-Object -ComObject Shell.Application
try {
$EA = $ErrorActionPreference; $ErrorActionPreference = 'Stop'
$objNewIE = $objShellApp.Windows() | ?{$_.HWND -eq $HWND}
$objNewIE.Visible = $true
} catch {
#it may happen, that the Shell.Application does not find the window in a timely-manner, therefore quick-sleep and try again
Write-Host "Waiting for page to be loaded ..."
Start-Sleep -Milliseconds 500
try {
$objNewIE = $objShellApp.Windows() | ?{$_.HWND -eq $HWND}
$objNewIE.Visible = $true
} catch {
Write-Host "Could not retreive the -com Object InternetExplorer. Aborting." -ForegroundColor Red
$objNewIE = $null
}
} finally {
$ErrorActionPreference = $EA
$objShellApp = $null
}
return $objNewIE
}
$HWND = ($objIE = New-Object -ComObject InternetExplorer.Application).HWND
$objIE.Navigate("https://www.google.com")
$objIE = ConnectIExplorer -HWND $HWND