删除自身

代码
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;

 

posted @ 2010-01-18 10:02  谭志宇  阅读(218)  评论(0)    收藏  举报