当已经打开默认窗口时,如何在新的IE窗口中打开IE选项卡

时间:2014-09-09 22:51:04

标签: internet-explorer batch-file tabs

好的,我正在处理BAT文件,而且我遇到了一个问题。

这是我的BAT文件:

@ECHO *************WELCOME BACK*******************

@PAUSE 

@ECHO OFF 

START /d iexplore http://V.P.N url

|||||this creates a window that has to stay opened for my V.P.N access

@PAUSE 

START /d iexplore 1

START /d iexplore 2

||| these sites load as tabs which perfect

此问题出现在此部分。我需要它做的是打开一个全新的IE窗口,后续的URL将作为新窗口中的选项卡打开,但是当我运行BAT时它会打开一个新窗口,但它会打开第一个IE窗口中的所有选项卡( vpn,工具1和2)

@PAUSE 

START /d iexplore -new site1

PING 1.1.1.1 -n 3 -w 2000>NUL

START /d iexplore site2 

START /d iexplore site3

START /d iexplore site 4 

是否知道如何将第二个IE窗口设置为默认值,以便新选项卡将加载到新窗口?

这适用于IE8。

1 个答案:

答案 0 :(得分:0)

我无法在Windows 8上测试它,但这个"应该"工作或至少可以用作一个解决方案的骨架

这是一个混合批处理/ jscript文件。将其另存为.cmd.bat并执行它。根据需要进行调整

@if (@this==@isBatch) @then
@echo off

    rem search internet explorer
    for /f "tokens=2,*" %%a in ('
        reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\IEXPLORE.EXE" /ve
        ^|find "REG_"
    ') do set "iexplore=%%b"


    rem Start the VPN instance 
    start "" "%iexplore%" -new http://www.example.com/vpn
    rem Let internet explorer initialize this instance
    timeout /t 2 > nul

    rem Start a new explorer window
    start "" "%iexplore%" -new http://www.example.com/mySite
    rem Let internet explorer initialize this instance
    timeout /t 2 > nul


    rem Now, load a new set of addresses into the last opened window
    cscript //nologo //e:jscript "%~f0" /url:"http://www.example.com/mySite2"
    cscript //nologo //e:jscript "%~f0" /url:"http://www.example.com/mySite3"
    cscript //nologo //e:jscript "%~f0" /url:"http://www.example.com/mySite4"
    cscript //nologo //e:jscript "%~f0" /url:"http://www.example.com/mySite5"

    exit /b

@end //== javascript zone ======================================================= 
    // Values to be used in the Navigate() method
    var navOpenInNewTab         = 0x0800
      , navOpenInBackgroundTab  = 0x1000
      , navOpenNewForegroundTab = 0x10000;

    // Retrieve command line arguments
    var url = WScript.Arguments.Named.Item("url");

    // Instantiate component to get access to shell
    var shellApplication = new ActiveXObject('Shell.Application');

    // Retrieve the last window
    var windows = new Enumerator(shellApplication.Windows());
    var w = null;
    while (!windows.atEnd()){w = windows.item(); windows.moveNext()};

    // If a window is found, use this window to open the url in a new tab, 
    // else create a iexplore instance to load the url
    if (w){
        w.Navigate(url, navOpenNewForegroundTab, '_blank');
    } else {
        with (new ActiveXObject('WScript.Shell')){
            Run('"' 
                + RegRead('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE\\')
                + '" -new "' + url + '"'
            )
        }
    };
    // Let everything initialize before exit
    WScript.Sleep(500);