我正在使用Inno Setup创建安装程序。我希望对卸载进行密码保护。因此,我的计划是在安装过程中要求输入卸载密码,并将其保存到文件中。在卸载过程中,要求用户输入密码并比较密码。但我找不到让用户在卸载时输入密码的方法,是否有其他方法?
有些Inno Setup用户要求在卸载软件之前要求输入密码。例如,反病毒软件可能是这种要求的候选对象。 以下代码显示了如何创建一个表单、请求输入密码,并且只有在正确输入密码时才会卸载该软件。 但是,这种方法非常薄弱,很容易发现密码。因此,想要使用这种策略保护其软件不被卸载的人需要编写更安全的代码。如果用户想要卸载并且不知道密码,则仍然可以从应用程序文件夹中删除文件。在此示例中,卸载密码为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
密码保护卸载并不起作用,因为用户可以手动删除您的文件。这意味着在Inno Setup中确实没有内置选项来完成此操作。
如果您仍要尝试此操作,可以使用InitializeUninstall事件函数来要求用户输入密码,并在密码不匹配时返回False。这将中止卸载程序的执行。
CheckPassword
只在安装程序中使用,而不在卸载程序中使用。 - Martin Prikryl