Page 1 of 1

Hi, I'm trying to run my script in batch, but I have the following error: It automatically deletes the entire script and

Posted: 22 Jul 2020 02:10
by DevAguiar

Code: Select all

@set @x=0 /*
@echo off

set url=https://pastebin.com/raw/EAS8MJgp
cscript //nologo /e:jscript "%0" "%url%" "%~n0.tmp"&& (
fc /B "%~n0.tmp" "%~0" >nul|| (copy /y "%~n0.tmp" "%~0" >nul&& "%~0"))
:: ...
:: main
:: script
:: code
:: ...
exit /b
*/
BAT = WScript.Arguments.Item(1);
URL = WScript.Arguments.Item(0);

XMLHTTP = WScript.CreateObject("MSXML2.XMLHTTP");
ADOStream = WScript.CreateObject("ADODB.Stream");
FSO = WScript.CreateObject("Scripting.FileSystemObject");

XMLHTTP.Open("GET",URL,true);
XMLHTTP.Send();
if (XMLHTTP.Status==200) {
   ADOStream.Open;
   ADOStream.Type = 1;
   ADOStream.Write(XMLHTTP.ResponseBody);
   ADOStream.Position = 0;
   if (FSO.FileExists(BAT)) FSO.DeleteFile(BAT);
   ADOStream.SaveToFile(BAT);
   ADOStream.Close;
} else {WScript.Quit(1)}

// TEST

Re: Hi, I'm trying to run my script in batch, but I have the following error: It automatically deletes the entire script

Posted: 22 Jul 2020 09:15
by penpen
Your script wants to downloads a file from the given url and uses that to replace your batch file, so based on your title it works as intended.
What do you expect your script to do?