gpt4 book ai didi

java - 尝试在 Windows 中卸载我的 Java 应用程序时询问密码

转载 作者:可可西里 更新时间:2023-11-01 10:31:57 25 4
gpt4 key购买 nike

我已经为我的 Windows java 应用程序制作了一个安装程序。在 Windows 中安装后一切正常。现在我想添加一项功能,该功能应该在我尝试卸载我的应用程序时要求输入密码,如果没有密码,肯定无法卸载它。

我想知道的另一件事是,我是否需要制作一个单独的卸载程序,或者我是否可以在我的安装程序本身中添加这些功能?

如有任何帮助,我们将不胜感激。

P.S. 此处我针对 Windows 操作系统安装应用程序。

In short, I want that if someone tries to uninstall my application, he prompted for a password and if he enters the right password then and then he can able to uninstall it.

I don't know to achieve above want, whether I need to change my installer or I need to create a custom uninstaller.

最佳答案

最后,经过如此多的努力,我找到了一些很好的资源,可以向我解释所有问题。

在 Inno Setup pascal 脚本中,我可以修改一些代码来实现密码保护,如下所示:

[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;

信息来源:this post

关于java - 尝试在 Windows 中卸载我的 Java 应用程序时询问密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52517384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com