35

I want to open a particular URL without directly opening the browser using only a batch file. I know I can use something like:

START www.google.com

But I want to open a URL without using a browser. Is this possible?

The reason is that I have to open like 30 URLs, and I don't want the user to have like 30 tabs opened on his/her pc.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
comb
  • 463
  • 1
  • 4
  • 13
  • 1
    You can use wget or curl, see http://superuser.com/questions/25538/what-is-the-windows-equivalent-of-wget – Jakub Kotowski Dec 26 '13 at 09:59
  • 5
    What is your real intention? "Open a URL", to me, means opening a browser page to allow user to browse it. – LS_ᴅᴇᴠ Dec 26 '13 at 10:03
  • 3
    If you don't use a browser then you will not see the `www.google.com` page. Are you doing something else, like downloading files? – foxidrive Dec 26 '13 at 12:48
  • possible duplicate of [perform httprequest in batch file](http://stackoverflow.com/questions/4284866/perform-httprequest-in-batch-file) – Ganesh Sittampalam Apr 19 '15 at 20:54
  • What do you mean by "open a URL without using a browser"? What should happen? For example, should the corresponding HTML content be saved to disk? If yes, what about other content (images, CSS, JavaScript, etc.)? – Peter Mortensen Sep 19 '19 at 16:43
  • Use a dedicated Chromium instance. – 9pfs Aug 04 '21 at 23:42

8 Answers8

42

If all you want is to request the URL and if it needs to be done from batch file, without anything outside of the OS, this can help you:

@if (@This==@IsBatch) @then
@echo off
rem **** batch zone *********************************************************

    setlocal enableextensions disabledelayedexpansion

    rem The batch file will delegate all the work to the script engine
    if not "%~1"=="" (
        wscript //E:JScript "%~dpnx0" %1
    )

    rem End of batch file area. Ensure the batch file ends execution
    rem before reaching the JavaScript zone
    exit /b

@end


// **** JavaScript zone *****************************************************
// Instantiate the needed component to make URL queries
var http = WScript.CreateObject('Msxml2.XMLHTTP.6.0');

// Retrieve the URL parameter
var url = WScript.Arguments.Item(0)

// Make the request

http.open("GET", url, false);
http.send();

// All done. Exit
WScript.Quit(0);

It is just a hybrid batch/JavaScript file and is saved as callurl.cmd and called as callurl "http://www.google.es". It will do what you ask for. No error check, no post, just a skeleton.

If it is possible to use something outside of the OS, wget or curl are available as Windows executables and are the best options available.

If you are limited by some kind of security policy, you can get the Internet Information Services (IIS) 6.0 Resource Kit Tools. It includes tinyget and wfetch tools that can do what you need.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MC ND
  • 69,615
  • 8
  • 84
  • 126
  • Works like a charm for my use, much appreciated MC ND! – Martin S. Stoller Jun 10 '14 at 23:15
  • 2
    For one wondering, how does this work, %~dpnx0 specifies the full path to the current file being run, so we're calling into wscript to run this as a JavaScript file via ( //E:engine ), where the chosen engine is JavaScript, and %1 is the first parameter of the batch file, which this is passing forward. Interesting solution. – Greg Feb 13 '15 at 15:39
  • Where in this script do you actually define the URL you want to request? – square_eyes Apr 24 '15 at 20:53
  • 2
    @square_eyes, as indicated, it is passed as argument to the batch file. You can replace all the references to `%1` (the first argument to the batch file) with the url you want (don't forget quotes if it contains special characters) – MC ND Apr 24 '15 at 20:59
  • Where in the script I can set the URL that I want to request ? – Edson Rodrigues Dec 03 '15 at 17:17
  • 1
    @EdsonRodrigues, If you don't want to use the indicated behaviour (the url is given as the argument when calling the batch file) replace in the code `%1` (the first argument to the batch file) with the url you want to use (better quote it to avoid problems with special characters). – MC ND Dec 03 '15 at 17:44
  • @MCND Thanks for the answer. So, I have changed the %1 to "http://www.google.com" ( just to test ), It gives me an Access denied when I execute the cmd file. – Edson Rodrigues Dec 03 '15 at 18:04
  • 2
    @EdsonRodrigues, try changing the instantiated component. Replace `Msxml2.XMLHTTP.6.0` with `Msxml2.ServerXMLHTTP.6.0` – MC ND Dec 06 '15 at 09:52
  • 1
    @MCND Great solution thanks. I have one question though, I am using this to kill a selenium server, however sometimes selenium might die on its own and i want to schedule this task, now if the server is dead the URL used to kill it can't be accessed so i get an error box appear "The system cannot locate the resource specified" that makes perfect sense since the server is inactive, but how can i dismiss that message box or suppress it? I've had a quick look and couldn't see anything but i might be searching for the wrong thing. Thanks again. – Sirk Dec 23 '16 at 10:45
  • 2
    @Sirk, check [this](http://stackoverflow.com/a/39590203/2861476). You will not need the quote handling, but the code includes the error handling – MC ND Dec 23 '16 at 11:44
17

You can use Wget or cURL, see How to download files from command line in Windows like wget or curl.

You will then do e.g.:

wget www.google.com
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jakub Kotowski
  • 7,411
  • 29
  • 38
  • Somehow the link in your post gets automatically redirected to - http://superuser.com/questions/25538/how-to-download-files-from-command-line-in-windows-like-wget-is-doing – RBT Dec 18 '16 at 12:11
  • 1
    @RBT someone edited that post: http://superuser.com/posts/25538/revisions – Jakub Kotowski Dec 18 '16 at 19:57
  • 1
    wget and curl are not included in stock/vanilla windows, so not always a great option if you're trying to share a quick/easy script with others... step 1: download these other tools and configure them (seems like a big pain for an "easy" script solution). – m1m1k Apr 26 '18 at 09:43
17

You can use the HH command to open any website.

hh <http://url>

For example,

hh http://shuvankar.com

Though it will not open the website in the browser, but this will open the website in an HTML help window.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Shuvankar Sarkar
  • 409
  • 4
  • 11
  • works great to just hit a website to log an IP or kick off a script. *Note* that (as OP said, ) User does not see the website, and has to close the awkward help popup saying "Page not found". – m1m1k Apr 26 '18 at 09:44
  • @Shuvankar Sarkar, after call this, how do I close the popup HTML help window in script? – Abdullah Nurum Mar 24 '19 at 03:10
  • Is there a way to invoke this in background without the GUI – Akshay Shah Apr 23 '19 at 09:39
12

Not sure whether you have already gotten your owner solution. I have been using the following powshell command to achieve it:

powershell.exe -noprofile -command "Invoke-WebRequest -Uri http://your_url"
Fengzmg
  • 710
  • 8
  • 9
5

Try winhttpjs.bat. It uses a winhttp request object that should be faster than
Msxml2.XMLHTTP as there isn't any DOM parsing of the response. It is capable to do requests with body and all HTTP methods.

call winhttpjs.bat  http://somelink.com/something.html -saveTo c:\something.html
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • how to use in linux – Gem Dec 07 '17 at 14:21
  • 2
    Winhttpjs.bat is one of my favorites! @Gem winhttpjs.bat is a tool designed for batch, which is a Windows-Only coding language. On linux there is bash on which there are built-in tools such as `curl` or `wget` to get the job done. – Mark Deven Feb 27 '20 at 18:50
2

You can use this command:

start /min iexplore http://www.google.com

With the use of /min, it will hit on the URL without opening in the browser.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

The perfect solution with curl

curl www.google.com
Hack1
  • 5
  • 3
-4

You can try put in a shortcut to the site and tell the .bat file to open that.

start Google.HTML
exit
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Morgan
  • 25
  • 1
  • 9
    OP asks for a solution that does not open i a browser, and have already said that he knows the START command, and that he does not like the result – Squazz Oct 05 '15 at 08:59