【问题标题】:Select IE window using HWND使用 HWND 选择 IE 窗口
【发布时间】:2016-08-27 10:59:48
【问题描述】:

想知道是否可以根据 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}

$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

【问题讨论】:

  • 你所说的“合作”是什么意思?你是要关注新窗口还是要使用InternetExplorer.Applicationcomobjects 来控制它?
  • 我想用InternetExplorer.Application com对象来控制新窗口

标签: powershell internet-explorer com hwnd


【解决方案1】:

Shell.Application中搜索Windows()可以得到IE的comobject。

$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")

【讨论】:

  • 谢谢,很遗憾我的代码无法按预期工作。将我的代码添加到原始帖子中。
  • 您是否尝试过使用LocationName(网站标题)或LocationURL(如果您知道您想要的网址的某些部分)?然后你可以一起跳过 hwnd-search++。前任。查看更新的答案
  • 你试过$shell.windows()吗?这。您可以找到要搜索的内容。如果它丢失了,那你就不走运了。
  • 是的,所以当我只使用$shell.windows() 时,控制台不会返回任何内容。但是,当我要求 count 时,它会返回 1。奇怪...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2013-07-13
  • 1970-01-01
  • 2021-12-23
  • 2011-08-14
  • 2013-01-17
相关资源
最近更新 更多