使用Inno Setup实现密码保护卸载

6
我正在使用Inno Setup创建安装程序。我希望对卸载进行密码保护。因此,我的计划是在安装过程中要求输入卸载密码,并将其保存到文件中。在卸载过程中,要求用户输入密码并比较密码。但我找不到让用户在卸载时输入密码的方法,是否有其他方法?

你找到任何解决方案吗?我想实现同样的功能。 - Jay Patel
3个回答

5

有些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


1
源代码已经失效。这里是 WayBackMachine 的捕获链接:https://web.archive.org/web/20160416025247/http://www.vincenzo.net/isxkb/index.php?title=Require_an_uninstallation_password - Xel Naga
1
啊,好老的协作方式。喜欢它。谢谢。 - vicsar

1

密码保护卸载并不起作用,因为用户可以手动删除您的文件。这意味着在Inno Setup中确实没有内置选项来完成此操作。

如果您仍要尝试此操作,可以使用InitializeUninstall事件函数来要求用户输入密码,并在密码不匹配时返回False。这将中止卸载程序的执行。


我找不到让用户在卸载时输入密码的方法。(我尝试使用CreateInputQueryPage,但是它一直报错)。如何在卸载时从用户处获取输入? - Navaneeth

-1
您可以在Inno Setup帮助中查找“CheckPassword”函数。

CheckPassword 只在安装程序中使用,而不在卸载程序中使用。 - Martin Prikryl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接