How do I access the classic Internet Explorer COM automation object for a running instance of Internet Explorer from Powershell?

故事扮演 提交于 2019-12-06 03:48:21

Usually, to obtain access to a COM interface on an existing object, you would use the running object table. Unfortunately, Internet Explorer doesn't register itself with the running object table - but nevertheless, this provides us with some useful Google search results.

For example, Googling "running object table" "internet explorer" found me How to connect to a running instance of Internet Explorer which provides a (VBScript?) sample demonstrating the use of the ShellWindows object.

A quick 'n dirty (no error checking!) translation of this sample to PowerShell script gives us:

$shellapp = New-Object -ComObject "Shell.Application"
$ShellWindows = $shellapp.Windows()
for ($i = 0; $i -lt $ShellWindows.Count; $i++)
{
  if ($ShellWindows.Item($i).FullName -like "*iexplore.exe")
  {
    $ie = $ShellWindows.Item($i)
    break
  }
}
$ie.navigate2("http://stackoverflow.com")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!