Registriert seit: 18. Apr 2004
637 Beiträge
|
Re: Eine exe löscht sich selbst!
13. Sep 2008, 14:53
Hi, die .bat könnte auch ins temp-Verzeichnis geschrieben werden.
Delphi-Quellcode:
uses
ShellAPI;
procedure DeleteSelf;
function GetTmpDir: string;
var
pc: PChar;
begin
pc := StrAlloc(MAX_PATH + 1);
GetTempPath(MAX_PATH, pc);
Result := string(pc);
StrDispose(pc);
end;
function GetTmpFileName(ext: string): string;
var
pc: PChar;
begin
pc := StrAlloc(MAX_PATH + 1);
GetTempFileName(PChar(GetTmpDir), 'DeleteSelf', 0, pc);
Result := string(pc);
Result := ChangeFileExt(Result, ext);
StrDispose(pc);
end;
var
BatchFile: TStringList;
BatchFileName: string;
begin
BatchFileName := GetTmpFileName('.bat');
FileSetAttr(ParamStr(0), 0);
BatchFile := TStringList.Create;
with BatchFile do
begin
try
Add('@echo off');
Add(':retry');
Add(Format('Erase "%s"', [ParamStr(0)]));
Add(Format('If exist "%s" Goto retry', [ParamStr(0)]));
Add(Format('Erase "%s"', [BatchFileName]));
SaveToFile(BatchFileName);
ShellExecute(0, 'Open', PChar(BatchFileName), nil, nil, SW_HIDE);
finally
BatchFile.Free;
end;
Halt;
end;
end;
|
|
Zitat
|