使用 Inno Setup 进行密码保护卸载

发布于 2024-08-24 04:07:01 字数 117 浏览 4 评论 0原文

我正在使用 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉薄对峙 2024-08-31 04:07:01

某些 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;

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

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

遗失的美好 2024-08-31 04:07:01

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

如果您想尝试此操作,您可以使用 InitializeUninstall 事件函数来询问用户密码,并在不匹配时返回 False。这将中止卸载程序。

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.

那一片橙海, 2024-08-31 04:07:01

您可以在 Inno Setup 帮助中查看“CheckPassword”功能。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文