如何防止使用其他安装目录重新安装以创建第二次安装?

时间:2014-06-17 18:04:24

标签: install4j

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

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

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

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

谢谢, 彼得

1 个答案:

答案 0 :(得分:1)

您可以添加"运行脚本"检查您是否更新以前的安装的操作。

// 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;    
相关问题