How to launch multiple Internet Explorer windows/tabs from batch file?
Thanks for the tip Rodger.
For me it worked as below:
@echo off
start /d "" IEXPLORE.EXE www.google.com
start /d "" IEXPLORE.EXE www.yahoo.com
With the settings in Internet Explorer 8:
- always open popups in a new tab
- a new tab in the current window
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
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:
- 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.
- 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.)