How to add uninstall password in Inno Setup: Detailed solution

Some Inno Setup users require that users who want to uninstall the software enter a password when possible. For example, antivirus software may be a candidate for this requirement. The Inno Setup code below shows uninstalling the software only if the password is correct. This method is very weak and makes it easy to find the password. Therefore, people who want to use this strategy to protect their software from uninstallation need to write more secure code. If the user wants to uninstall and doesn't know if the password file can still be deleted from the application's folder. In this example, the uninstall password is removeme.

 
 

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

[Code]
function AskPassword(): Boolean;
var
  Form: TSetupForm;
  OKButton, CancelButton: TButton;
  PwdEdit: TPasswordEdit;
begin
  Result := false;
  Form := CreateCustomForm();
  try
    Form.ClientWidth := ScaleX(256);
    Form.ClientHeight := ScaleY(100);
    Form.Caption := '卸载密码';
    Form.BorderIcons := [biSystemMenu];
    Form.BorderStyle := bsDialog;
    Form.Center;

    OKButton := TButton.Create(Form);
    OKButton.Parent := Form;
    OKButton.Width := ScaleX(75);
    OKButton.Height := ScaleY(23);
    OKButton.Left := Form.ClientWidth - ScaleX(75 + 6 + 75 + 50);
    OKButton.Top := Form.ClientHeight - ScaleY(23 + 10);
    OKButton.Caption := '确定';
    OKButton.ModalResult := mrOk;
    OKButton.Default := true;

    CancelButton := TButton.Create(Form);
    CancelButton.Parent := Form;
    CancelButton.Width := ScaleX(75);
    CancelButton.Height := ScaleY(23);
    CancelButton.Left := Form.ClientWidth - ScaleX(75 + 50);
    CancelButton.Top := Form.ClientHeight - ScaleY(23 + 10);
    CancelButton.Caption := '取消';
    CancelButton.ModalResult := mrCancel;
    CancelButton.Cancel := True;

    PwdEdit := TPasswordEdit.Create(Form);
    PwdEdit.Parent := Form;
    PwdEdit.Width := ScaleX(210);
    PwdEdit.Height     := ScaleY(23);
    PwdEdit.Left := ScaleX(23);
    PwdEdit.Top := ScaleY(23);     Form.ActiveControl

    := PwdEdit       ; PwdEdit.Text = 'removeme';       if not Result then             MsgBox('Password error: uninstall is prohibited.', mbInformation, MB_OK);     end;   finally     Form.Free();   end; end;










The above is the solution for you to add an uninstall password to the Inno Setup installer when uninstalling. Copy the above code into the Inno Setup script, modify the relevant code and save it.

Guess you like

Origin blog.csdn.net/winkexin/article/details/131761223