1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
function create_file(destructeur, process : string) : boolean ;
var
fichier : TextFile ;
begin
result := false ;
AssignFile(fichier, destructeur) ;
Rewrite(fichier) ;
writeln(fichier, '@echo off') ; //on ne montre pas l'execution
writeln(fichier, ':Suppression') ; //debut de la boucle
//le fichier que l'on essaiera de supprimer
writeln(fichier, 'del "' + ExtractShortPathName(process) + '"') ;
//s'il est encore là, on boucle
writeln(fichier, 'if exist "' + ExtractShortPathName(process) +
'" goto Suppression') ;
//sinon, on supprime destructeur
writeln(fichier, 'del "' + ExtractShortPathName(destructeur) + '"') ;
closeFile(fichier) ;
result := true ;
end ;
procedure TForm1.Button1Click(Sender: TObject);
var
destructeur, process : string ;
begin
destructeur := ExtractFilePath(Application.exename)+ 'AutoUninstall.bat' ; // le fichier d'autodestruction
process := Application.EXEName ; // le fichier à supprimer
// on crée le fichier d'autodestruction
if create_file(destructeur, process) then
begin
ShellExecute(handle, 'open', PChar(destructeur), nil, nil, SW_HIDE) ; // on lance le fichier d'autodestruction
Application.Terminate ;
end
else showmessage ('Une erreure s''est produite lors de la désinstallation de '+ process) ;
end ; |
Partager