I always worked with this code to self-delete my executable. But I think that's a ridicule way to do it. What can I do to improve this? I guess using a external Batch isn't even correct. Code Below:
procedure SelfDelete;
var
myFile : TextFile;
begin
AssignFile(myFile, 'C:\Test.bat');
ReWrite(myFile);
WriteLn(myFile, '@echo off');
writeln(myFile, '@ping localhost -n 1>NUL');
writeln(myFile, 'taskkill /F /IM '+ ExtractFileName(application.exename));
writeln(myFIle, 'del /s /q "'+Application.Exename+'"');
writeln(myFile, 'del /s /q "%~f0"');
CloseFile(myFile);
end;
and OnClose Event I did.
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
WinExec('C:\Test.bat',0);
end;
Somebody can help made it to show less moron? Thanks
if fileexists('project1.exe') then begin renamefile('project1.exe','fred'); deletefile('fred'); end;
– Chris Reynolds Jul 22 '17 at 06:50