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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DevAguiar
Posts: 1
Joined: 22 Jul 2020 02:03

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

#1 Post by DevAguiar » 22 Jul 2020 02:10

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
Last edited by aGerman on 22 Jul 2020 04:58, edited 1 time in total.
Reason: code formatting

penpen
Expert
Posts: 1846
Joined: 23 Jun 2013 06:15
Location: Germany

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

#2 Post by penpen » 22 Jul 2020 09:15

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?

Post Reply