How can I perform a silent uninstallation as part of the upgrade process on Windows?

Answered

Comments

1 comment

  • Avatar
    Jake

    You can retrieve the path to the uninstaller from the Windows registry and storing it in an installer variable.

    <!-- In particular, this "${product_fullname} ${product_version}" string will make the installer detect its own previous installation. You will need to change it to match with the program and version you want to uninstall. -->
    

    <registryGetMatch>
        <key>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${product_fullname} ${product_version}</key>
        <name>UninstallString</name>
        <variable>uninstaller_path</variable>
    </registryGetMatch>

    Then, you can execute the path stored in ${uninstaller_path}, in case it exists:

    <!-- run the uninstaller program only if ${uninstaller_path} points to an existing file -->
    
    <runProgram>
    
        <program>${uninstaller_path}</program>
        <programArguments>--mode unattended</programArguments>
    
        <ruleList>
    
            <fileTest>
    
                <path>${uninstaller_path}</path>
    
                <condition>exists</condition>
    
            </fileTest>
    
        </ruleList>
    
    </runProgram>
    

    Similar solutions can be applied to detect a previous installation directory as well.

Please sign in to leave a comment.