如何从Powershell访问Internet Explorer的正在运行的实例的传统Internet Explorer COM自动化对象? [英] How do I access the classic Internet Explorer COM automation object for a running instance of Internet Explorer from Powershell?
问题描述
如何为正在运行的Internet Explorer实例访问传统Internet Explorer COM自动化对象?也就是说,如果我在多个窗口中打开Internet Explorer,那么如何在Powershell中将与这些窗口之一对应的COM对象与Powershell中的变量关联起来?我最近的做法是通过get-process获得进程iexplore和ieuser。
,要获取对现有对象上的COM接口的访问,您将使用正在运行的对象表。不幸的是,Internet Explorer不会注册自己运行的对象表 - 但尽管如此,这为我们提供了一些有用的Google搜索结果。
例如,Googling正在运行的对象表Internet Explorer找到了如何连接到Internet Explorer的正在运行的实例,它提供了一个(VBScript?)示例演示使用ShellWindows对象的示例。 p>
这个示例对PowerShell脚本的一个简单的检查(没有错误检查!)给我们:
$ shellapp = New-Object -ComObjectShell.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)
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.
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")
这篇关于如何从Powershell访问Internet Explorer的正在运行的实例的传统Internet Explorer COM自动化对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!