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

标签 java windows desktop-application uninstallation

我已经为我的 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/

相关文章:

windows - 如何从 `CEdit` 框获取通知?

java - Spring Boot 和安全 : How to extend response for 302 status code?

Qt - 具有键盘和鼠标事件透明度的顶级小部件?

java - 有没有办法从 Oracle Commerce(ATG) 中的文件系统加载组件?

windows - `git difftool` 拒绝在 Emacs 劣质外壳下运行

windows - 如何将包含扩展名的文件路径复制到 .txt 文件中

windows - 是否可以在 Linux 机器上编译 Windows 二进制文件?

c++ - 带有多行单元格的 QTableView

java - 在本地机器上运行 ignite

java - 使用 MongoDB 删除新数组并将其添加到 JSON 对象中