Powershell 使用HWND选择IE窗口
想知道是否可以基于HWND属性(或类似属性)选择IE窗口。我的脚本单击一个链接,该链接将在一个单独的窗口中打开一个新页面,我希望能够使用这个新窗口 这是我的密码:Powershell 使用HWND选择IE窗口,powershell,internet-explorer,com,hwnd,Powershell,Internet Explorer,Com,Hwnd,想知道是否可以基于HWND属性(或类似属性)选择IE窗口。我的脚本单击一个链接,该链接将在一个单独的窗口中打开一个新页面,我希望能够使用这个新窗口 这是我的密码: $ie.Navigate("https://chaseloanmanager.chase.com/Chaselock/ViewOnlineGuide.aspx") # opens page in new window while ($ie.Busy -eq $true){Start-Sleep -Seconds 2} $childW
$ie.Navigate("https://chaseloanmanager.chase.com/Chaselock/ViewOnlineGuide.aspx") # opens page in new window
while ($ie.Busy -eq $true){Start-Sleep -Seconds 2}
$childWindow = Get-Process | Where-Object {($_.ProcessName -eq 'iexplore')} | Get-ChildWindow | Where-Object {$_.ChildTitle -match 'Lending'}
$childWindow.MainWindowHandle # gets HWND of new window
$shell = New-Object -ComObject Shell.Application
$ie3 = $shell.Windows() | Where-Object {$_.HWND -match $childWindow.MainWindowHandle} # does not find window
您可以通过搜索
Shell.Application
中的Windows()
来获取IE对象
$shell = New-Object -ComObject Shell.Application
$ie = $shell.Windows() | Where-Object { $_.LocationURL -match 'Lending' }
#$ie = $shell.Windows() | Where-Object { $_.HWND -eq 2951084 }
$ie.Navigate("http://www.stackoverflow.com")
你说的“合作”是什么意思?您想关注新窗口,还是想使用
InternetExplorer.Application
comobject来控制它?我想使用InternetExplorer.Application
comobject来控制新窗口谢谢,很遗憾,我的代码无法按预期工作。将我的代码添加到原始帖子。您是否尝试使用LocationName
(网站标题)或LocationURL
(如果您知道url中您想要的唯一部分)?然后您可以一起跳过hwnd search+。查看更新的答案您是否尝试过$shell.windows()
?这个您可以找到要搜索的内容。如果它丢失了,那么你的运气就不好了。是的,所以当我只使用$shell.windows()
时,控制台不会返回任何东西。但是,当我询问计数时,它返回1
。古怪的