使用Inno Setup进行密码保护的卸载 [英] Password protected uninstallation using Inno Setup
问题描述
我正在使用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?
推荐答案
某些Inno Setup用户要求先要求要卸载软件的用户输入密码,然后再进行操作.例如,反病毒软件可能是此要求的候选者. 以下代码显示仅在密码正确的情况下如何创建表格,要求输入密码以及卸载软件的方法. 此方法非常弱,很容易找出密码.因此,想要使用此策略来保护其软件免受卸载的人,需要编写更安全的代码.如果用户要卸载并且不知道密码文件是否可以从应用程序的文件夹中删除.在此示例中,卸载密码为 removeme .
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;
来源: http://www.vincenzo.net/isxkb/index.php?title=Require_an_uninstallation_password
这篇关于使用Inno Setup进行密码保护的卸载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!