Abort installation if the program is already installed

Answered

Comments

2 comments

  • Avatar
    wojciechka

    You could make the installer check in the registry for a previous installation, and if found, call its uninstaller and exit. For Windows it is easiest to implement as Windows has a registry key and values that are set automatically by InstallBuilder:

    <registryGet> <key>HKEY_LOCAL_MACHINE\Software\${project.windowsSoftwareRegistryPrefix}</key> <name>Location</name> <variable>pre_installdir</variable> <ruleList> <platformTest type="windows"/> </ruleList> </registryGet> <runProgram program="${pre_installdir}/uninstall.exe"> <ruleList> <fileExists path="${pre_installdir}/uninstall.exe"/> </ruleList> </runProgram>

    Similarly you can <throwError> instead of <runProgram> action to show an error if the application is already installed.

    On Unix systems you may need to use a file - such as in /etc to store the installation information.

    You can use the following XML to store the value in an ini file that is using <vendor> and <shortName> from your project:

    <preInstallationActionList> <foreach> <values>version pre_version installdir pre_installdir</values> <variables>name variable</variables> <actionList> <setInstallerVariable name="${variable}" value=""/> <iniFileGet> <file>/etc/${project.vendor}-${project.shortName}.ini</file> <key>${name}</key> <section>details</section> <variable>${variable}</variable> <ruleList> <fileTest condition="exists" path="/etc/${project.vendor}-${project.shortName}.ini"/> </ruleList> </iniFileGet> </actionList> <ruleList> <platformTest negate="1" type="windows"/> </ruleList> </foreach> </preInstallationActionList>

    The above will read the ini file and store version and installdir in ${pre_version} and ${pre_installdir} accordingly.

    The following XML can be used to store the version in the ini file as well:

    <postInstallationActionList> <foreach> <values>version ${project.version} installdir ${installdir}</values> <variables>name variable</variables> <actionList> <iniFileSet> <file>/etc/${project.vendor}-${project.shortName}.ini</file> <key>${name}</key> <section>details</section> <value>${variable}</value> </iniFileSet> </actionList> <ruleList> <platformTest negate="1" type="windows"/> </ruleList> </foreach> <addFilesToUninstaller files="/etc/${project.vendor}-${project.shortName}.ini"/> </postInstallationActionList>

    1
    Comment actions Permalink
  • Avatar
    elad

    This is what I did:

        <preInstallationActionList>
                <throwError text="Please uninstall the old ${product_shortname} installtion">
                    <customErrorMessage>Please uninstall the old ${product_shortname} installtion</customErrorMessage>
                    <show>0</show>
                    <explanation>Please uninstall the old ${product_shortname} installtion</explanation>
                    <ruleList>
                        <fileExists>
                            <path>${installdir}/myjar.jar</path>
                        </fileExists>
                    </ruleList>         
                 </throwError>
            </preInstallationActionList>
    
    0
    Comment actions Permalink

Please sign in to leave a comment.