user3749626
user3749626

Reputation: 23

How do I prevent a re-install with different installation directory from creating a second installation?

This is currently a Windows only installer. I have "Detect previous installation" selected. I also have "Alert for update installation" in the Welcome screen disabled, and a condition on the "Install location" to avoid showing the dialog if context.isUpdateInstallation() is true.

But I can still change the installation directory through a response file on a silent install.

The result is that I have binary files in two directories, I only have one service (created by the installer) that points to the most recent installation directory, and two entries for my installer in the "Programs and Features".

The desired behavior would be that the binary files are moved to the new directory, and only one entry in "Programs and Features". I could live with the installer ignoring the new installation directory, and just ensure that all the files in the installation directory are there.

Thanks, Peter

Upvotes: 2

Views: 293

Answers (1)

Ingo Kegel
Ingo Kegel

Reputation: 48090

You can add a "Run script" action that checks if you're updating the previous installation or not.

// 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;    

Upvotes: 2

Related Questions