Open a URL without using a browser from a batch file
Solution 1
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.
Solution 2
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
Solution 3
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.
Solution 4
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"
Solution 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
comb
Updated on October 02, 2020Comments
-
comb over 3 years
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.
-
Martin S. Stoller about 10 yearsWorks like a charm for my use, much appreciated MC ND!
-
Greg over 9 yearsFor 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.
-
square_eyes about 9 yearsWhere in this script do you actually define the URL you want to request?
-
MC ND about 9 years@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) -
Squazz over 8 yearsOP 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
-
Edson Rodrigues over 8 yearsWhere in the script I can set the URL that I want to request ?
-
MC ND over 8 years@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). -
Edson Rodrigues over 8 years@MCND Thanks for the answer. So, I have changed the %1 to "google.com" ( just to test ), It gives me an Access denied when I execute the cmd file.
-
MC ND over 8 years@EdsonRodrigues, try changing the instantiated component. Replace
Msxml2.XMLHTTP.6.0
withMsxml2.ServerXMLHTTP.6.0
-
Peter Szekeli over 8 yearsThis solution still launches a browser (but keeps the focus on the current app).
-
RBT over 7 yearsSomehow the link in your post gets automatically redirected to - superuser.com/questions/25538/…
-
Jakub Kotowski over 7 years@RBT someone edited that post: superuser.com/posts/25538/revisions
-
Sirk over 7 years@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.
-
MC ND over 7 years@Sirk, check this. You will not need the quote handling, but the code includes the error handling
-
Gem over 6 yearshow to use in linux
-
m1m1k about 6 yearswget 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 about 6 yearsworks 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".
-
Abdullah Nurum over 5 years@Shuvankar Sarkar, after call this, how do I close the popup HTML help window in script?
-
Akshay Shah about 5 yearsIs there a way to invoke this in background without the GUI
-
Mark Deven over 4 yearsWinhttpjs.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
orwget
to get the job done. -
Chique about 4 yearsWow this worked like a charm. So simple, and just does the job.
-
Jeffz over 3 yearsTry that with https with self-signed cert using Task Scheduler and simplicity dies.