본문 바로가기
Delphi/프로시저-함수

실행파일 종료시 실행파일 삭제

by MonoSoft 2024. 3. 11.
728x90
반응형

실행파일 종료시 실행파일 삭제

728x90

 

 

 

procedure DeleteMe;

var

BatchFile:TextFile;

BatchFileName:String;

ProcessInfo:TProcessInformation;

StartUpInfo:TStartupInfo;

begin

BatchFileName:=ExtractFilePath(application.exename)+'$$336699.bat';

AssignFile(BatchFile, BatchFileName);

Rewrite(BatchFile);

Writeln(BatchFile, ':try');

Writeln(BatchFile, 'del "' + application.exename + '"');

Writeln(BatchFile, 'if exist "' + application.exename + '"' + ' goto try');

Writeln(BatchFile, 'del "' + BatchFileName + '"');

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;

//Close;

end;

 

====================================

procedure TForm1.Button1Click(Sender: TObject);

begin

DeleteMe;

Close;

end;

728x90
반응형

댓글