DeleteMe

程序删除自身

 

// 利用批处理文件构造一个循环,只要在 OnClose() 中调用 DeleteMe() 就可以删除自身
procedure DeleteMe();
var
   BatchFile: TextFile;
   BatchFileName:
string ;
   ProcessInfo: TProcessInformation;
   StartUpInfo: TStartupInfo;
begin
   BatchFileName :
= ExtractFilePath(ParamStr( 0 )) + ' _deleteme.bat ' ;
   AssignFile(BatchFile, BatchFileName);
   Rewrite(BatchFile);

   Writeln(BatchFile,
' :try ' );
   Writeln(BatchFile,
' del " ' + ParamStr( 0 ) + ' " ' );
   Writeln(BatchFile,
    
' if exist " ' + ParamStr( 0 ) + ' " ' + ' goto try ' );
   Writeln(BatchFile,
' del %0 ' );
   CloseFile(BatchFile);

   FillChar(StartUpInfo, SizeOf(StartUpInfo), $
00 );
   StartUpInfo.dwFlags :
= STARTF_USESHOWWINDOW;
   StartUpInfo.wShowWindow :
= SW_HIDE;
  
if CreateProcess( nil , PChar(BatchFileName), nil , nil , False, IDLE_PRIORITY_CLASS, nil , nil , StartUpInfo, ProcessInfo) then
  
begin
     CloseHandle(ProcessInfo.hThread);
     CloseHandle(ProcessInfo.hProcess);
  
end ;
end ;

你可能感兴趣的:(String,Class)