Java 在install4j中:AddInstallReventListener引发NotSupportedElevationException异常

Java 在install4j中:AddInstallReventListener引发NotSupportedElevationException异常,java,windows-8.1,install4j,Java,Windows 8.1,Install4j,在install4j中,在“运行脚本”操作中: 我有“操作提升类型”=“提升到最大可用权限” 调用context.addinstallerventListener(installerEventListener) 它在Win7中运行良好 但是它在Windows 8中抛出异常NotSupportedElevationException。当用户取消安装时,public void installerEvent(installerEvent事件){}中的所有代码都不会执行 Win7和Win8两种情况下

在install4j中,在“运行脚本”操作中:

  • 我有“操作提升类型”=“提升到最大可用权限”
  • 调用
    context.addinstallerventListener(installerEventListener)
它在Win7中运行良好

但是它在Windows 8中抛出异常
NotSupportedElevationException
。当用户取消安装时,
public void installerEvent(installerEvent事件){}
中的所有代码都不会执行

Win7和Win8两种情况下的用户帐户(执行安装程序)是管理员


这是Windows 8中install4j的问题吗?

在Windows 7中,UAC被禁用,因此不会启动提升的帮助程序进程

您必须在不相关的代码中执行context.AddInstallReventListener。你可以打电话

context.runUnelevated(new RemoteCallable() {
    public Serializable execute() {
        context.addInstallerEventListener(new InstallerEventListener() {
            public void installerEvent(InstallerEvent installerEvent) {
                // TODO
            }
        });
        return null;
    }
});

在提升代码中。

感谢Ingo提供的提示帮助。我的解决方案是:

  • 将RunScript操作的“操作提升类型”设置为“不提升”
  • 正常调用
    AddInstallReventListener
    (不在未提升模式下)
  • 在RunHighted方法中重新启动某些服务

  • 重要提示:必须同步重新启动服务,因此install4j VM必须等待此过程结束后才能终止。

    Put context.addInstallReventListener()在runUnelevated中,不再出现异常NotSupportedElevationException。但是我想在public void installerent(installerent installerent){//Runtime.getRuntime().exec(fileBat)}中启动一些Windows服务,它似乎什么都不做。在fileBat中,我有一些行命令,如:net start“serviceName”,然后您必须在不相关的代码中注册侦听器,并使用context.runhiveled启动Windows服务。
    public void installerEvent(InstallerEvent installerEvent) {
          context.runElevated(new RemoteCallable() {
              @Override
              public Serializable execute() {
                  Process process = Runtime.getRuntime().exec(startServicesBatchFile);
                  process.waitFor();
              }
          }, true);
      }