开发者

Password protected uninstallation using Inno Setup

I am making an installer using Inno Setup. I wan开发者_StackOverflow中文版t to password protect the uninstallation. So my plan is to ask for the uninstallation password during installation, and save it into a file. While uninstalling, ask for the password from user and compare the passwords.

I could not find a way to let the user enter the password while uninstalling, is there any?


Some Inno Setup users require that the user who wants to uninstall the software is asked for a password before this is possible. Anti virus software might be a candidate for this requirement, for instance. The code below shows how to create a form, ask for a password, and uninstall the software only if the password is correct. This method is very weak, it's easy to find out the password. So, someone who wants to use this strategy to protect his software from uninstallation needs to code something safer. If the user wants to uninstall and doesn't know the password files could be deleted anyway from the application's folder. In this sample the uninstall password is removeme.

[Setup]
AppName=UninsPassword
AppVerName=UninsPassword
DisableProgramGroupPage=true
DisableStartupPrompt=true
DefaultDirName={pf}\UninsPassword

[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 := 'Uninstall Password';
    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 := 'OK';
    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 := 'Cancel';
    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;

    if Form.ShowModal() = mrOk then
    begin
      Result := PwdEdit.Text = 'removeme';
      if not Result then
            MsgBox('Password incorrect: Uninstallation prohibited.', mbInformation, MB_OK);
    end;
  finally
    Form.Free();
  end;
end;


function InitializeUninstall(): Boolean;
begin
  Result := AskPassword();
end;

Source: http://www.vincenzo.net/isxkb/index.php?title=Require_an_uninstallation_password


Password protecting uninstallations doesnt work, since the user can simply manually delete your files. This means there's indeed no built in option in Inno Setup to do this.

If you want to attempt this anyway you could use an InitializeUninstall event function to ask the user for a password and return False on mismatch. This will abort the uninstaller.


You can check for the "CheckPassword" function in the Inno Setup help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜