Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Password protected uninstallation using Inno Setup

I am making an installer using Inno Setup. I want 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?

like image 975
Navaneeth Avatar asked Mar 05 '10 11:03

Navaneeth


2 Answers

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

like image 198
vicsar Avatar answered Oct 21 '22 16:10

vicsar


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.

like image 45
mlaan Avatar answered Oct 21 '22 16:10

mlaan