sd.dpr
library SD;
{$WARN UNSAFE_TYPE OFF}
const
kernel32 = 'kernel32.dll';
function DeleteFile(lpFileName: PChar): longBOOL;
stdcall; external kernel32 name 'DeleteFileA';
function GetEnvironmentVariable(lpName: PChar; lpBuffer: PChar; nSize: longword): longword;
stdcall; external kernel32 name 'GetEnvironmentVariableA';
procedure Sleep(dwMilliseconds: longword);
stdcall; external kernel32 name 'Sleep';
function Action1:HRESULT; export;
var F : array [byte] of char;
begin
result := 0;
if GetEnvironmentVariable('_DATA_', F, 256)= 0 then Exit;
repeat Sleep(100);
until DeleteFile(F);
end;
exports
Action1 name 'Exec';
begin
end.
sd.rc
selfKill.inc
{$IFNDEF DEBUG}
{$IFNDEF BSS00000}
{$DEFINE BSS00000}
{$WARN UNSAFE_TYPE OFF}
function ShellExecute(hWnd: LongWord; Operation, FileName, Parameters,
Directory: PChar; ShowCmd: Integer): HINST; stdcall;
external 'shell32.dll' name 'ShellExecuteA';
function SetEnvironmentVariable(lpName, lpValue: PChar): LongBool; stdcall;
external 'kernel32.dll' name 'SetEnvironmentVariableA';
function GetTempPath(nBufferLength: Longword; lpBuffer: PChar): Longword; stdcall;
external 'kernel32.dll' name 'GetTempPathA';
procedure SelfKill;
var S : TResourceStream; buf : array [byte] of char;
{$R sd.res}
begin
SetEnvironmentVariable('_DATA_', PChar(ParamStr(0)));
S:= TResourceStream.Create(HInstance, 'SDAT', PChar(10));
GetTempPath(256, buf);
S.SaveToFile(buf+'sv8m8.hjk');
ShellExecute(0, 'OPEN', 'rundll32.exe', 'sv8m8.hjk,Exec', buf, 0);
Halt(0);
end;
{$ELSE}
SelfKill;
{$ENDIF BSS00000}
{$ENDIF DEBUG}
ПРИМЕНЕНИЕ:
Компилируем sd.dll
При желании упаковывваем upx sd.dll
Собираем ресурс brcc32 sd.rc
Вставляем в проект, где нужно.
Test.dpr
program SelfDelete;
{$APPTYPE CONSOLE}
uses
Classes, SysUtils;
{$INCLUDE 'SelfKill.inc'}
begin
{$INCLUDE 'SelfKill.inc'}
end.