1

I would like to send an automatic url request, using a VBS or a BATCH file. The request will have this structure : http://myServeurIP/Test/?name=ezioauditore

I found this post, to help me : Open a URL without using a browser from a batch file

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

    setlocal enableextensions disabledelayedexpansion

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

    rem End of batch area. Ensure batch ends execution before reaching
    rem 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);

But I don't understand. What is "%~1"=="" ? I put my URL in http.send(http://myServeurIP/Test/);. Is it correct ? Also I have no visibility if it works or not.

Can you help me understand this script ?

Community
  • 1
  • 1
Tofuw
  • 908
  • 5
  • 16
  • 35

1 Answers1

1

Everything above @end is not specific to the problem at hand ... it's a way of making the script runnable as either a batch file, or a script directly.

If you want to hard-code the URL in the script and will be running it with an explicit "wscript.exe _script_ //E:Jscript", it can be a lot shorter, something like the following...

var http = WScript.CreateObject('Msxml2.XMLHTTP.6.0');
http.open("GET", "http://myServeurIP/Test/", false);
http.send();
WScript.Quit(0);
david
  • 997
  • 6
  • 15