【问题标题】:Ask for password when try to uninstall my java application in Windows尝试在 Windows 中卸载我的 java 应用程序时询问密码
【发布时间】:2019-03-02 05:04:26
【问题描述】:

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

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

任何帮助将不胜感激。

P.S.这里我的目标是 Windows 操作系统来安装应用程序。

简而言之,我希望如果有人试图卸载我的应用程序,他会提示输入密码,如果他输入正确的密码然后 然后他就可以卸载了。

我不知道实现上面想要的,是否需要改变我的 安装程序,或者我需要创建一个自定义卸载程序。

【问题讨论】:

  • 我理解正确吗,您将“卸载程序”编写为 java 程序,现在想用密码保护该程序?
  • 不,我只是创建了一个“安装程序”,我不知道如何创建一个“卸载程序”如果你知道如何创建卸载程序请分享资源。
  • 如果您知道应用程序的安装位置,您可以使用java.io.File.delete() 删除您创建的所有文件。
  • @TA 我正在寻找一些在卸载时要求输入密码的解决方案。我不想删除任何文件,实际上我正在尝试使我的安装更安全
  • 对我来说听起来像是XY Problem。你最终想要完成什么?

标签: java windows desktop-application uninstallation


【解决方案1】:

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

在 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 2015-06-07
    • 2011-08-19
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    相关资源
    最近更新 更多