首页 文章

在现有IE实例中打开选项卡

提问于
浏览
11
$ie = New-Object -com internetexplorer.application

每次我用这个对象打开一个新网站(即每次脚本运行时)都会在新的IE窗口中打开,我不希望它这样做 . 我希望它在一个新的选项卡中打开,但在以前打开的IE窗口中也是如此 . 我想在下次运行脚本时重用此对象 . 我不想创建一个新对象

那么有什么方法可以检查Internet Explorer的实例并重用其实例???

I tried this as a solution:

首先,您必须附加到已经运行的Internet Explorer实例:

$ie = (New-Object -COM "Shell.Application").Windows() `
    | ? { $_.Name -eq "Windows Internet Explorer" }

然后导航到新URL . 打开该URL的位置是通过Flags参数控制的:

$ie.Navigate("http://www.google.com/", 2048)

但是我无法在这个新创建的对象 $ie 上调用 navigate 方法 .

3 回答

  • 8

    您可以使用 Start-Process 打开URL . 如果浏览器窗口已打开,它将作为选项卡打开 .

    Start-Process 'http://www.microsoft.com'
    
  • 10

    首先,您必须附加到已经运行的Internet Explorer实例:

    $ie = (New-Object -COM "Shell.Application").Windows() `
            | ? { $_.Name -eq "Windows Internet Explorer" }
    

    然后你Navigate到新的URL . 打开该URL的位置是通过Flags参数控制的:

    $ie.Navigate("http://www.google.com/", 2048)
    

    Edit: 如果有2个或更多IE实例正在运行(其他选项卡也计入其他实例),枚举将返回一个数组,因此您必须从数组中选择一个特定实例:

    $ie[0].Navigate("http://www.google.com/", 2048)
    
  • 2

    如果Internet Explorer不是您的默认浏览器,则可以使用此选项:

    Function Open-IETabs {
        param (
            [string[]]$Url
        )
        begin {
            $Ie = New-Object -ComObject InternetExplorer.Application
        }
        process {
            foreach ($Link in $Url) {
                $Ie.Navigate2($Link, 0x1000)
            }
        }
        end {
            $Ie.Visible = $true
        } 
    }
    

    我在PowerShell.com找到了这个

相关问题