如何从Powershell访问正在运行的Internet Explorer实例的经典Internet Explorer COM自动化对象?

时间:2023-01-27 11:30:39

How do I access the classic Internet Explorer COM automation object for a running instance of Internet Explorer? That is, if I have Internet Explorer open in multiple windows, how do I associate the COM object corresponding to one of those windows with a variable in Powershell, from within Powershell? The closest I have come to doing this is obtaining the processes "iexplore" and "ieuser" via get-process.

如何为正在运行的Internet Explorer实例访问经典Internet Explorer COM自动化对象?也就是说,如果我在多个窗口中打开Internet Explorer,如何在Powershell中将与其中一个窗口对应的COM对象与Powershell中的变量相关联?我最接近这样做的是通过get-process获取进程“iexplore”和“ieuser”。

1 个解决方案

#1


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.

通常,要获取对现有对象的COM接口的访问权限,您将使用运行对象表。不幸的是,Internet Explorer没有在运行对象表中注册自己 - 但是,这为我们提供了一些有用的Google搜索结果。

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.

例如,谷歌搜索“运行对象表”“Internet Explorer”找到我如何连接到正在运行的Internet Explorer实例,它提供了一个演示ShellWindows对象使用的(VBScript?)示例。

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

快速'肮脏(无错误检查!)此示例到PowerShell脚本的转换为我们提供了:

$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://*.com")

#1


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.

通常,要获取对现有对象的COM接口的访问权限,您将使用运行对象表。不幸的是,Internet Explorer没有在运行对象表中注册自己 - 但是,这为我们提供了一些有用的Google搜索结果。

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.

例如,谷歌搜索“运行对象表”“Internet Explorer”找到我如何连接到正在运行的Internet Explorer实例,它提供了一个演示ShellWindows对象使用的(VBScript?)示例。

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

快速'肮脏(无错误检查!)此示例到PowerShell脚本的转换为我们提供了:

$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://*.com")