How to launch multiple Internet Explorer windows/tabs from batch file?

248,953

Solution 1

Try this in your batch file:

@echo off
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE www.google.com
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE www.yahoo.com

Solution 2

You can use either of these two scripts to open the URLs in separate tabs in a (single) new IE window. You can call either of these scripts from within your batch script (or at the command prompt):

JavaScript
Create a file with a name like: "urls.js":

var navOpenInNewWindow = 0x1;
var navOpenInNewTab = 0x800;
var navOpenInBackgroundTab = 0x1000;

var intLoop = 0;
var intArrUBound = 0;
var navFlags = navOpenInBackgroundTab;
var arrstrUrl = new Array(3);
var objIE;

    intArrUBound = arrstrUrl.length;

    arrstrUrl[0] = "http://bing.com/";
    arrstrUrl[1] = "http://google.com/";
    arrstrUrl[2] = "http://msn.com/";
    arrstrUrl[3] = "http://yahoo.com/";

    objIE = new ActiveXObject("InternetExplorer.Application");
    objIE.Navigate2(arrstrUrl[0]);

    for (intLoop=1;intLoop<=intArrUBound;intLoop++) {

        objIE.Navigate2(arrstrUrl[intLoop], navFlags);

    }

    objIE.Visible = true;
    objIE = null;


VB Script
Create a file with a name like: "urls.vbs":

Option Explicit

Const navOpenInNewWindow = &h1
Const navOpenInNewTab = &h800
Const navOpenInBackgroundTab = &h1000

Dim intLoop       : intLoop = 0
Dim intArrUBound  : intArrUBound = 0
Dim navFlags      : navFlags = navOpenInBackgroundTab

Dim arrstrUrl(3)
Dim objIE

    intArrUBound = UBound(arrstrUrl)

    arrstrUrl(0) = "http://bing.com/"
    arrstrUrl(1) = "http://google.com/"
    arrstrUrl(2) = "http://msn.com/"
    arrstrUrl(3) = "http://yahoo.com/"

    set objIE = CreateObject("InternetExplorer.Application")
    objIE.Navigate2 arrstrUrl(0)

    For intLoop = 1 to intArrUBound

        objIE.Navigate2 arrstrUrl(intLoop), navFlags

    Next

    objIE.Visible = True
    set objIE = Nothing


Once you decide on "JavaScript" or "VB Script", you have a few choices:

If your URLs are static:

1) You could write the "JS/VBS" script file (above) and then just call it from a batch script.

From within the batch script (or command prompt), call the "JS/VBS" script like this:

cscript //nologo urls.vbs
cscript //nologo urls.js


If the URLs change infrequently:

2) You could have the batch script write the "JS/VBS" script on the fly and then call it.


If the URLs could be different each time:

3) Use the "JS/VBS" scripts (below) and pass the URLs of the pages to open as command line arguments:

JavaScript
Create a file with a name like: "urls.js":

var navOpenInNewWindow = 0x1;
var navOpenInNewTab = 0x800;
var navOpenInBackgroundTab = 0x1000;

var intLoop = 0;
var navFlags = navOpenInBackgroundTab;
var objIE;
var intArgsLength = WScript.Arguments.Length;

    if (intArgsLength == 0) {

        WScript.Echo("Missing parameters");
        WScript.Quit(1);

    }

    objIE = new ActiveXObject("InternetExplorer.Application");
    objIE.Navigate2(WScript.Arguments(0));

    for (intLoop=1;intLoop<intArgsLength;intLoop++) {

        objIE.Navigate2(WScript.Arguments(intLoop), navFlags);

    }

    objIE.Visible = true;
    objIE = null;


VB Script
Create a file with a name like: "urls.vbs":

Option Explicit

Const navOpenInNewWindow = &h1
Const navOpenInNewTab = &h800
Const navOpenInBackgroundTab = &h1000

Dim intLoop
Dim navFlags      : navFlags = navOpenInBackgroundTab
Dim objIE

    If WScript.Arguments.Count = 0 Then

        WScript.Echo "Missing parameters"
        WScript.Quit(1)

    End If

    set objIE = CreateObject("InternetExplorer.Application")
    objIE.Navigate2 WScript.Arguments(0)

    For intLoop = 1 to (WScript.Arguments.Count-1)

        objIE.Navigate2 WScript.Arguments(intLoop), navFlags

    Next

    objIE.Visible = True
    set objIE = Nothing


If the script is called without any parameters, these will return %errorlevel%=1, otherwise they will return %errorlevel%=0. No checking is done regarding the "validity" or "availability" of any of the URLs.


From within the batch script (or command prompt), call the "JS/VBS" script like this:

cscript //nologo urls.js "http://bing.com/" "http://google.com/" "http://msn.com/" "http://yahoo.com/"
cscript //nologo urls.vbs "http://bing.com/" "http://google.com/" "http://msn.com/" "http://yahoo.com/"

OR even:

cscript //nologo urls.js "bing.com" "google.com" "msn.com" "yahoo.com"
cscript //nologo urls.vbs "bing.com" "google.com" "msn.com" "yahoo.com"


If for some reason, you wanted to run these with "wscript" instead, remember to use "start /w" so the exit codes (%errorlevel%) will be returned to your batch script:

start /w "" wscript //nologo urls.js "url1" "url2" ...
start /w "" wscript //nologo urls.vbs "url1" "url2" ...


Edit: 21-Sep-2016

There has been a comment that my solution is too complicated. I disagree. You pick the JavaScript solution, or the VB Script solution (not both), and each is only about 10 lines of actual code (less if you eliminate the error checking/reporting), plus a few lines to initialize constants and variables.

Once you have decided (JS or VB), you write that script one time, and then you call that script from batch, passing the URLs, anytime you want to use it, like:

cscript //nologo urls.vbs "bing.com" "google.com" "msn.com" "yahoo.com"

The reason I wrote this answer, is because all the other answers, which work for some people, will fail to work for others, depending on:

  1. The current Internet Explorer settings for "open popups in a new tab", "open in current/new window/tab", etc... Assuming you already have those setting set how you like them for general browsing, most people would find it undesirable to have change those settings back and forth in order to make the script work.
  2. Their behavior is (can be) inconsistent depending on whether or not there was an IE window already open before the "new" links were opened. If there was an IE window (perhaps with many open tabs) already open, then all the new tabs would be added there as well. This might not be desired.

The solution I provided doesn't have these issues and should behave the same, regardless of any IE Settings or any existing IE Windows. (Please let me know if I'm wrong about this and I'll try to address it.)

Solution 3

Of course it is an old post but just for people who will find it through a search engine.

Another solution is to run it like this for IE9 and later

iexplore.exe" -noframemerging http://google.com
iexplore.exe" -noframemerging http://gmail.com

-noframemerging means run IE independently. For example if you want to run 2 browsers and login as different usernames it will not work if you just run 2 IE. But with -noframemerging it will work.

-noframemerging works for IE9 and later, for early versions like IE8 it is -nomerge

Usually I create 1 bat file like this run_ie.bat

"c:\Program Files (x86)\Internet Explorer\iexplore.exe" -noframemerging %1

and I create another bat file like this run_2_ie.bat

start run_ie.bat http://google.com
start run_ie.bat http://yahoo.com

Solution 4

This worked for me:

start /d IEXPLORE.EXE www.google.com
start /d IEXPLORE.EXE www.yahoo.com

But for some reason opened them up in Firefox instead?!?

I tried this but it merely opened up sites in two different windows:

start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE www.google.com
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE www.yahoo.com
Share:
248,953
user1055201
Author by

user1055201

Updated on June 17, 2021

Comments

  • user1055201
    user1055201 almost 3 years

    I would like a batch file to launch two separate programs then have the command line window close. Actually, to clarify, I am launching Internet Explorer with two different URLs.

    So far I have something like this:

    start "~\iexplore.exe" "url1"
    start "~\iexplore.exe" "url2"
    

    What I get is one instance of Internet Explorer with only the second URL loaded. Seems the second is replacing the second. I seem to remember a syntax where I would load a new command line window and pass the command to execute on load, but can't find the reference.

    As a second part of the question: what is a good reference URL to keep for the times you need to write a quick batch file?

    Edit: I have marked an answer, because it does work. I now have two windows open, one for each URL. (thanks!) The funny thing is that without the /d approach using my original syntax I get different results based on whether I have a pre-existing Internet Explorer instance open.

    • If I do I get two new tabs added for my two URLs (sweet!)
    • If not I get only one final tab for the second URL I passed in.
  • Stephen P
    Stephen P over 13 years
    See help start in cmd.exe : the parameter to the /d argument is the path of the starting directory -- that is, what to set the current directory to before starting the command. What your first command says is "Start up www.google.com after setting the current dir to IEXPLORE.EXE". Using start with just a URL launches whatever you've configured as your preferred web browser; that's why it opened Firefox.
  • Rodger Cooley
    Rodger Cooley almost 13 years
    It furnished the startup path for the executable.
  • Jon Burchel
    Jon Burchel almost 13 years
    The proposed answer by Rodger did not work for me. It does open the URL in Internet Explorer, but in my case (with IE 9) it still opens a new window each time it is called, even if I have the IE options set to open links from other programs in a new tab in the current window. :(
  • Terrible Tadpole
    Terrible Tadpole over 7 years
    This is way over-complicated. You can do it simply in a CMD batch script. I've added the solution as a comment to the marked answer.
  • Terrible Tadpole
    Terrible Tadpole over 7 years
    You can make it work exactly as you want like this: ` @echo off start "link" www.google.com start "link" www.yahoo.com ` If no browser is open the default browser will be invoked with the first URL. If the browser is open (which it will be for your second and subsequent commands) then the URL will be opened in a new tab.
  • Terrible Tadpole
    Terrible Tadpole over 7 years
    Dammit... line-break required before each start command. I couldn't make them show in the comment, and ran out of editing time trying.
  • Kevin Fegan
    Kevin Fegan over 7 years
    @TerribleTadpole - I couldn't get this to work. I tried start "link" www.google.com && start "link" www.yahoo.com. Internet Explorer opens with only 1 tab showing the second link (yahoo). This is exactly the same situation the OP has described and is trying to work around. If I add a delay between the 2 start commands like this: start "link" www.google.com && sleep 5 && start "link" www.yahoo.com, Internet Explorer opens with only 1 tab showing the first link (google), then after a few seconds Internet Explorer opens another window with only 1 tab showing the second link (yahoo).
  • Kevin Fegan
    Kevin Fegan over 7 years
    @TerribleTadpole - I tried your proposed solution-as-comment, and it didn't work for me. I left a comment there with details. Even if it did work, there are issues: 1) If there was an IE window open (perhaps with many open tabs) before the first start command, then all the new tabs would be added there as well. This might not be desired. 2) Making it work for this batch, probably would require changing IE settings for "popups" and/or "open in new window/tab". Those changes are not nice if you already have IE setup how you generally like it to work.
  • Kevin Fegan
    Kevin Fegan over 7 years
    @TerribleTadpole - Perhaps it would work if I changed IE settings for "popups" and/or "open in new window/tab" (or other settings), but I have those settings set how I like them for general browser use, and I wouldn't want to change that just to make the batch script work.
  • KuronosuKami
    KuronosuKami almost 3 years
    Been looking for something like this and the examples do exactly what I was hoping they would. However, when I replace the URLs and run any of both scripts, the first two URLs are actually opened and then there's an "Unspecified error" in Line 26, character 9 (Code 80004005). I'm actually trying to open four local URLs; three of them "http:// 172....xbap" and one "https://.....loc/". However, any combination of them (even if it's just four times the .loc address) results in that error after opening the first two URLs/tabs. I wonder if there's a solution or a way to slow the script down...
  • Kevin Fegan
    Kevin Fegan almost 3 years
    @KuronosuKami - You didn't mention which browser and browser version you are using. This solution was written over 7 hears ago, specifically for Internet Explorer, probably IE Version 8 or 9. I'm not sure how well it works with later versions, or other browsers like Chrome or Edge. Let me know which browser and browser version your targeting and I'll try to find a solution for you. Also do I understand that this works for you now (June 2021) if you use the URLs I mentioned as examples in the answer: "bing.com", "google.com", "msn.com", "yahoo.com" ?