如何从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。
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.
推荐答案
通常要获取对现有对象的COM接口的访问权限,可以使用正在运行的对象表。不幸的是,Internet Explorer没有注册自己的运行对象表 - 但是,这为我们提供了一些有用的Google搜索结果。
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.
例如,Googling运行对象表internet explorer找到我如何连接到运行的Internet Explorer实例,该实例提供了一个演示使用ShellWindows对象的(VBScript?)示例。
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.
将此示例快速(无错误检查!)转换为PowerShell脚本给我们:
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屋!