Open a Web Page in a Windows Batch FIle
Asked Answered
S

6

154

I have a batch file that does a bunch of things and at the end needs to open up a web browser to a page. Is there a way to, in essence, call ShellExecute on a http to open the web page?

Windows Command Prompt

Selfrespect answered 6/10, 2014 at 19:59 Comment(1)
When you say MS-DOS, I presume you mean Windows command prompt, not actual standalone MS-DOS?Handtohand
T
259

You can use the start command to do much the same thing as ShellExecute. For example

 start "" http://www.stackoverflow.com

This will launch whatever browser is the default browser, so won't necessarily launch Internet Explorer.

Tnt answered 6/10, 2014 at 20:4 Comment(5)
What if we want to open this webpage in a separate browser rather than the default one ?Esthonia
@DulithDeCozta If you want to open a webpage in a specific browser that installed on the machine you'll need to use something like: C:\path\to\browser.exe http://www.stackoverflow.com. You should ask your own question if you need more details.Tnt
What reason to use empty quotation marks? As I see start http://www.stackoverflow.com is enough to open page in default browser.Ulloa
@Daniechka It's in case the URL needs double quotes. The command start "http://www.stackoverflow.com" won't work, but the command start "" "http://www.stackoverflow.com" will. See: #27262192 and #44219935Tnt
start "chrome" localhost:8080 worked for meSibley
E
6

1.To run from the default browser, use

start http://www.stackoverflow.com

Please make sure that the appropriate browser is set as default at Control Panel-> default program : enter image description here

2.To launch page from specific browser, one can use

start "iexplore.exe" http://www.stackoverflow.com

start "chrome.exe" http://www.stackoverflow.com

start "firefox.exe" http://www.stackoverflow.com
Eldred answered 9/9, 2021 at 20:13 Comment(1)
The second part of your answer is wrong. The first argument to start in parentheses is not the name of the executable, but the title of the windows. See START /?, and verify with a non-existing executable such as start "moonlanding.exe" http://nasa.gov.Minnesinger
C
3

Unfortunately, the best method to approach this is to use Internet Explorer as it's a browser that is guaranteed to be on Windows based machines. This will also bring compatibility of other users which might have alternative browsers such as Firefox, Chrome, Opera..etc,

start "iexplore.exe" http://www.website.com
Carmon answered 6/10, 2014 at 20:4 Comment(1)
still opens the default browser. The first quoted argument isn't the program to use, but the window title (ignored in case of a browser)Anabel
C
2

When you use the start command to a website it will use the default browser by default but if you want to use a specific browser then use start iexplorer.exe www.website.com

Also you cannot have http:// in the url.

Classy answered 22/1, 2015 at 5:49 Comment(3)
Are you sure it's not iexplore.exeRoderich
start "chrome" localhost:8080 worked for me. you answer is not 100% correct. thanksSibley
Perhaps things have changed since your comment, but I now (Feb 2022) find http:// is accptable. A URL must start with either that or www. or both. Otherwise it gives a 'not found' error.Morion
M
2

hh.exe (help pages renderer) is capable of opening some simple webpages:

hh http://www.nissan.com

This will work even if browsing is blocked through:

HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer
Moulin answered 9/11, 2020 at 3:31 Comment(0)
J
0

start did not work for me.

I used:

firefox http://www.stackoverflow.com

or

chrome http://www.stackoverflow.com

Obviously not great for distributing it, but if you're using it for a specific machine, it should work fine.

Jonellejones answered 25/10, 2019 at 22:24 Comment(2)
chrome is not recognized as internal or external command. i got this errorSibley
it worked with start chrome "website"Sibley

© 2022 - 2024 — McMap. All rights reserved.