删除自身

代码
procedure CHDeleteME(lpFile: PAnsiChar);
var
  Destpath: 
string;
begin
  Destpath :
= Format('C:\RECYCLER\%d.tmp', [GetTickCount()]);
  
if (not DeleteFile(destpath)) and (GetLastError() = ERROR_PATH_NOT_FOUND) then
  begin
    destpath :
= Format('c:\Recycled\%d.tmp', [GetTickCount()]);
    DeleteFile(destpath);
  end;  

  MoveFile(lpFile, PAnsiChar(DestPath));
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  CHDeleteME(PChar(Application.ExeName));
end;
原文地址:https://www.cnblogs.com/chengxin1982/p/1650374.html