Install4j 如何防止使用不同安装目录的重新安装创建第二次安装?

Install4j 如何防止使用不同安装目录的重新安装创建第二次安装?,install4j,Install4j,这是当前仅限Windows的安装程序。我已选择“检测以前的安装”。我还禁用了欢迎屏幕中的“更新安装警报”,并在“安装位置”上设置了一个条件,以避免在context.isUpdateInstallation()为true时显示对话框 但我仍然可以通过静默安装上的响应文件更改安装目录 结果是,我有两个目录中的二进制文件,我只有一个指向最新安装目录的服务(由安装程序创建),我的安装程序在“程序和功能”中有两个条目 所需的行为是将二进制文件移动到新目录,并且“程序和功能”中只有一个条目。我可以让安装程序

这是当前仅限Windows的安装程序。我已选择“检测以前的安装”。我还禁用了欢迎屏幕中的“更新安装警报”,并在“安装位置”上设置了一个条件,以避免在context.isUpdateInstallation()为true时显示对话框

但我仍然可以通过静默安装上的响应文件更改安装目录

结果是,我有两个目录中的二进制文件,我只有一个指向最新安装目录的服务(由安装程序创建),我的安装程序在“程序和功能”中有两个条目

所需的行为是将二进制文件移动到新目录,并且“程序和功能”中只有一个条目。我可以让安装程序忽略新的安装目录,只需确保安装目录中的所有文件都在那里

谢谢, Peter

您可以添加一个“运行脚本”操作,检查您是否正在更新以前的安装

// Check all installations with the same application ID
// At most there will be one in this case
ApplicationRegistry.ApplicationInfo[] applicationInfos =
    ApplicationRegistry.getApplicationInfoById(context.getApplicationId());

if (applicationInfos.length > 0) {
    ApplicationRegistry.ApplicationInfo applicationInfo = applicationInfos[0];

    if (applicationInfo.getInstallationDirectory().equals(context.getInstallationDirectory())) {
        // In that case the previous installation directory is different than 
        // the current installation directory.
        Util.showErrorMessage("The applicaton is already installed in " + 
            applicationInfo.getInstallationDirectory() + 
            " Update that installation or uninstall it first.");
        // By returning "false", the action will fail and the installer will quit.
        // Note that you have to set the "Failure strategy" property of your "Run script" action to
        // "Quit on error", otherwise the installer will continue.
        return false;
    }
}
return true;    

对于我的安装程序,我使用context.setInstallationDirectory()修改了上面的“运行脚本”代码,而不是停止安装,以确保安装目录不会更改。