【问题标题】:How do I access the classic Internet Explorer COM automation object for a running instance of Internet Explorer from Powershell?如何从 Powershell 访问 Internet Explorer 运行实例的经典 Internet Explorer COM 自动化对象?
【发布时间】:2010-10-16 09:56:19
【问题描述】:

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

【问题讨论】:

    标签: internet-explorer dom com powershell


    【解决方案1】:

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

    例如,谷歌搜索“运行对象表”“Internet Explorer”找到了我How to connect to a running instance of Internet Explorer,它提供了一个(VBScript?)示例,演示了 ShellWindows 对象的使用。

    将此示例快速转换为 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://stackoverflow.com")
    

    【讨论】:

    • 我真的很想用 JScript 来做这件事。你知道有什么好的资源吗?
    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 2020-07-11
    • 2018-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多