Delphi - 改进我的代码以自行删除可执行文件

时间:2017-07-21 17:07:28

标签: delphi batch-file delphi-7 self-destruction

我总是使用此代码自行删除我的可执行文件。但我认为这是一种嘲笑的方式。我该怎么做才能改善这一点?我猜使用外部批处理甚至不正确。代码如下:

  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;

和OnClose事件我做了。

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
WinExec('C:\Test.bat',0);
end;

有人可以帮助它显示更少的白痴吗?感谢

0 个答案:

没有答案