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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Registry;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
PathAppli : String;
NameAppli : String;
FileSupp:TextFile;
Reg:TRegistry;
implementation
{$R *.dfm}
procedure TForm1.BtnDesinstallerClick(Sender: TObject);
begin
//Création du .bat
assignfile(FileSupp,PathAppli+'supp.bat');
rewrite(FileSupp);
writeln(FileSupp,'del "'+PathAppli+NameAppli+'"');
writeln(FileSupp,'del "'+PathAppli+'supp.bat"');
closefile(FileSupp);
//Création de la clé registre
//Suppression du programme lors du prochain redémarrage de Windows
//ATTENTION : AUNCUN ACCENT AUTORISE (ni pour le programme, ni pour le chemin)
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if Reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',True)then
begin
Reg.WriteString('supp','"'+PathAppli+'supp.bat"');
Reg.CloseKey;
Reg.Free;
end;
Application.Terminate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//Récupération du Chemin et du nom de l'application
PathAppli:=ExtractFilePath(ParamStr(0));
NameAppli:= ExtractFileName(ParamStr(0));
end;
end. |
Partager