1

Says the url is wrong but it seems right to me. I'm trying to download a file from the internet launch the program, then after the process ends to delete the program. Any help would be great

process will be

start exe ---> to create the simple downloader ---> add parameters via bat file ---> launch the file -----> wait for the process to end -----> delete the files downloaded. I have yet to add the wait process and delete commands

@if (@X)==(@Y) @end /****** jscript comment ******

@echo off
::::::::::::::::::::::::::::::::::::
:::       compile the script    ::::
::::::::::::::::::::::::::::::::::::
setlocal
if exist simpledownloader.exe goto :skip_compilation

set "frm=%SystemRoot%\Microsoft.NET\Framework\"
:: searching the latest installed .net framework
for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
    if exist "%%v\jsc.exe" (
        rem :: the javascript.net compiler
        set "jsc=%%~dpsnfxv\jsc.exe"
        goto :break_loop
    )
)
echo jsc.exe not found && exit /b 0
:break_loop


call %jsc% /nologo /out:"simpledownloader.exe" "%~dpsfnx0"
::::::::::::::::::::::::::::::::::::
:::       end of compilation    ::::
::::::::::::::::::::::::::::::::::::
:skip_compilation

:: download the file


::
::::::::::
:: simpledownloader.exe "%%~1" "%%~2"

simpledownloader.exe  "https://download.splashtop.com/sos/SplashtopSOS.exe" sos.exe
sos.exe

:: del /q simpledownloader.exe
::
::::::::
::

exit /b 0


****** end of jscript comment ******/

import System;
var arguments:String[] = Environment.GetCommandLineArgs();
var webClient:System.Net.WebClient = new System.Net.WebClient();
print("Downloading " + arguments[1] + " to " + arguments[2]);
try {
    webClient.DownloadFile(arguments[1], arguments[2]);
} catch (e) {

        Console.BackgroundColor = ConsoleColor.Green;
        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine("\n\nProblem with downloading " + arguments[1] + " to " + arguments[2] + "Check if the internet address is valid");
        Console.ResetColor();
        Environment.Exit(5);
}
fidk
  • 23
  • 4
  • You should still be using `:: simpledownloader.exe "%~1" "%~2"`, not `:: simpledownloader.exe "%%~1" "%%~2`. I also would not want to download anything via `http://` as opposed to `https://`. – Compo Dec 17 '20 at 15:35
  • Most importantly, I'm not sure if you're aware, but you appear to be trying to use a batch file as a hybrid cmd/js file, but do not appear to have separated one from the other in such a way as each are seen as the correct syntax for their respective interpreters/engines. You have used, `****** end of jscript comment ******/`, but have not included anything which defines the start of the jscript comment, like `@set @x=0 /*`, or `@if (true == false) @end /*`, for instance. – Compo Dec 17 '20 at 15:47
  • Do you think, it could be a tls issue? I'm pretty green, how would I force tls 1.2 – fidk Dec 17 '20 at 16:22
  • I think the main issue was what I told you! You had copied a code snippet from a hybrid cmd/js file, and omitted some of it. Now you've added that code, you may have a different issue, but as you've provided no debugging information, I've no intention of just giving you another thing to fix, then another and so on, until you tell me its all working as you wanted. This is a technical site, you should understand that your role in this question is to provide us with everything we need in order to ourselves reproduce your issue, "Says the url is wrong" is just not a sufficient way to do that. – Compo Dec 17 '20 at 17:30
  • @Compo It was just a bad copy and paste sorry about that...I fixed it above. – fidk Dec 17 '20 at 17:34
  • All we need now is an edit to provide the rest of the information we need! BTW, what on earth is `%%~dpsnfxv` supposed to represent? – Compo Dec 17 '20 at 17:35
  • I would like it to download a file, it does not do that with https://download.splashtop.com/sos/SplashtopSOS.exe however it does with http://download.teamviewer.com/download/TeamViewer_Setup_en.exe my only conclusion is that it is a tls issue, I don't have any other debugging information. – fidk Dec 17 '20 at 17:49
  • %%~dpsnfxv is to compile it in to an exe – fidk Dec 17 '20 at 17:54
  • No `%%~dpsnfxv` is not, it is a very very bad representation of the location of the parent directory for your compiler. Please open a Command Prompt window, type `for /?`, press the `[ENTER]` key, and read the usage information for the command. You currently have no idea what any of your code is supposed to do, if you scroll down that output, you should clearly see the modifiers, and a description of what each does. – Compo Dec 17 '20 at 18:00
  • Sorry, like I said I'm not in my element (or green) I'm following https://stackoverflow.com/questions/26926114/how-to-download-exe-file-from-web-and-run-it-with-some-script – fidk Dec 17 '20 at 18:03
  • I'm going to assume that your error message is, `Problem with downloading https://download.splashtop.com/sos/SplashtopSOS.exe to sos.exeCheck if the internet address is valid`, in red on a green background. I would therefore suggest that you change `Console.WriteLine("\n\nProblem with downloading " + arguments[1] + " to " + arguments[2] + "Check if the internet address is valid");` to `Console.WriteLine("\n\nProblem with downloading " + arguments[1] + " to " + arguments[2] + " Check if the internet address is valid");`. It isn't a fix for your issue, but it is a small improvement nonetheless! – Compo Dec 17 '20 at 21:22

1 Answers1

1

I think I found something for you I made some adjustments for you. Happy scripting!

 @echo off
 IF EXIST sos.exe goto delete 
 IF NOT EXIST sos.exe goto skip
 :delete
 echo delete
 del /f sos.exe 
 timeout 5
 :skip
 echo skip
 rem :: the first argument is the script name as it will be used for proper help message
 cscript //E:JScript //nologo "%~f0" "%~nx0" %*
 start sos.exe
 exit /b %errorlevel%
 
 
 
@if (@X)==(@Y) @end JScript comment */

// global variables and constants
var ARGS = WScript.Arguments;
var scriptName=ARGS.Item(0);

var url="";
var saveTo="";

var user=0;
var pass=0;

var proxy=0;
var bypass="";
var proxy_user=0;
var proxy_pass=0;
var certificate=0;
var force=true;

//ActiveX objects
//Use the right version of MSXML
/*var progIDs = [ 'Msxml2.DOMDocument.6.0', 'Msxml2.DOMDocument.5.0', 'Msxml2.DOMDocument.4.0', 'Msxml2.DOMDocument.3.0', 'Msxml2.DOMDocument' ]
for (var i = 0; i < progIDs.length; i++) {
 try {
     var XMLHTTPObj = new ActiveXObject(progIDs[i]);
 }catch (ex) {       
 }
}

if typeof  XMLHTTPObj === 'undefined'{
 WScript.Echo ("You are using too ancient windows or you have no installed IE");
 WScript.Quit(1);
}*/

var XMLHTTPObj = new ActiveXObject("MSXML2.XMLHTTP");
var FileSystemObj = new ActiveXObject("Scripting.FileSystemObject");
var AdoDBObj = new ActiveXObject("ADODB.Stream");


function existsItem(path){
 return FileSystemObj.FolderExists(path)||FileSystemObj.FileExists(path);
}

stripTrailingSlash = function(path){
 while (path.substr(path.length - 1,path.length) == '\\') {
     path=path.substr(0, path.length - 1);
 }
 return path;
}

function deleteItem(path){
 if (FileSystemObj.FileExists(path)){
     FileSystemObj.DeleteFile(path);
     return true;
 } else if (FileSystemObj.FolderExists(path) ) {
     FileSystemObj.DeleteFolder(stripTrailingSlash(path));
     return true;
 } else {
     return false;
 }
}

function writeFile(fileName,data ){
 AdoDBObj.Type = 1;       
 AdoDBObj.Open();
 AdoDBObj.Position=0;
 AdoDBObj.Write(data);
 AdoDBObj.SaveToFile(fileName,2);
 AdoDBObj.Close();   
}

function download( url,file){
 if (force && existsItem(file)){
     if(!deleteItem(file)){
         WScript.Echo("Unable to delete "+ file);
         WScript.Quit(8);
     }
 }else if (existsItem(file)){
     WScript.Echo("Item " + file + " already exist");
     WScript.Quit(9);
 }
 

 
 if (proxy!=0 && bypass !="") {
     //https://msdn.microsoft.com/en-us/library/ms760236(v=vs.85).aspx
     XMLHTTPObj.setProxy(SXH_PROXY_SET_DIRECT,proxy,bypass);
 } else if (proxy!=0) {
     XMLHTTPObj.setProxy(SXH_PROXY_SET_DIRECT,proxy,"");
 }
 

 
 if (proxy_user!=0 && proxy_pass!=0 ) {
     //https://msdn.microsoft.com/en-us/library/ms763680(v=vs.85).aspx
     XMLHTTPObj.setProxyCredentials(proxy_user,proxy_pass);
 }
 
 if(certificate!=0) {
     //https://msdn.microsoft.com/en-us/library/ms763811(v=vs.85).aspx
     WinHTTPObj.setOption(3,certificate);
 }
 
 if (user!=0 && pass!=0){
     //https://msdn.microsoft.com/en-us/library/ms757849(v=vs.85).aspx
      XMLHTTPObj.Open('GET',url,false,user,pass);
 } else {
     XMLHTTPObj.Open('GET',url,false);
 }
 
 
 
 XMLHTTPObj.Send();
 var status=XMLHTTPObj.Status;
 
 switch(status){
     case 200:
         WScript.Echo("Status: 200 OK");
         break;
     case 401:
         WScript.Echo("Status: 401 Unauthorized");
         WScript.Echo("Check if correct user and password were provided");
         WScript.Quit(401);
         break;
     case 407:
         WScript.Echo("Status:407 Proxy Authentication Required");
         WScript.Echo("Check if correct proxy user and password were provided");
         WScript.Quit(407);
         break;
     default:
         WScript.Echo("Status: "+status);
         WScript.Echo("Try to help yourself -> https://en.wikipedia.org/wiki/List_of_HTTP_status_codes");
         WScript.Quit(status);
 }
 writeFile(file,XMLHTTPObj.ResponseBody);
}

function main(){
 url="https://download.splashtop.com/sos/SplashtopSOS.exe"
 saveTo="sos.exe";

 download(url,saveTo);
}
  • 1
    I would run it though iexpress make it an exe for easier distribution, just make sure to whitelist it, some anti virus programs will flag this. – erghelpdesk Dec 22 '20 at 19:34