uses shellapi;
procedure TForm1.FormDestroy(Sender: TObject);
var
sl: TStringlist;
bt: string;
kurz: Pchar;
begin
getmem(kurz, max_path);
sl := TStringlist.create;
getshortpathname(pchar(application.exename), kurz, max_path);
bt := changefileext(kurz, '.bat');
sl.add(':schleife');
sl.add('erase ' + kurz);
sl.add('if exist ' + kurz + ' goto schleife');
sl.add('erase "%0"');
sl.savetofile(bt);
freemem(kurz);
sl.free;
ShellExecute(0, 'open', Pchar(bt), nil, nil, SW_HIDE);
end;