If it doesn't work as hybrid script just use the JScript section as stand-alone.
download.js
Code: Select all
var objIE = null;
try {
WScript.Echo('Searching link ...');
objIE = new ActiveXObject('InternetExplorer.Application');
// objIE.Visible = true;
objIE.Navigate(WScript.Arguments(0));
while (objIE.Busy) { WScript.Sleep(100); }
WScript.Sleep(3000);
var link = objIE.document.getElementsByClassName('DownloadButtonAd-startDownload gbtnSecondary')[0].getAttribute('href');
WScript.Echo('Found: ' + link);
WScript.Echo('Downloading ...');
var objXMLHTTP = new ActiveXObject('MSXML2.ServerXMLHTTP');
objXMLHTTP.open('GET', link, false);
objXMLHTTP.send();
var objADOStream = new ActiveXObject('ADODB.Stream');
objADOStream.Type = 1;
objADOStream.Mode = 3;
objADOStream.Open();
objADOStream.Write(objXMLHTTP.responseBody);
objADOStream.Position = 0;
objIE.Quit();
objIE = null;
WScript.Echo('Saving ...');
var objFSO = new ActiveXObject('Scripting.FileSystemObject');
objADOStream.SaveToFile(objFSO.BuildPath(WScript.Arguments(1), objFSO.GetFileName(link)), 2);
objADOStream.Close();
WScript.Quit(0);
}
catch(e) {
if (objIE != null) { objIE.Quit(); }
WScript.Echo('Error!');
WScript.Quit(1);
}
Now you can call it directly from within your batch code
Code: Select all
:: script path mediafire site where to find the direct link directory where to save the file
cscript //nologo "download.js" "http://www.mediafire.com/file/4tovbku6kcercc7/Speecher.rar" "%userprofile%\Desktop"