How can i leave a registry key if doing a partial uninstall?

Answered

Comments

1 comment

  • Avatar
    wojciechka

    InstallBuilder removes the entire registry key for the product after uninstallation. However, you can re-create a registry key in Post-uninstallation actions, which are run after the key is removed.

    For example you can register the key or keys both after installation and after uninstallation:

    <postInstallationActionList>
        <registrySet>
            <key>HKEY_LOCAL_MACHINE\\SOFTWARE\\${project.vendor}\\${project.fullName}</key>
            <name>DBSetup</name>
            <type>REG_SZ</type>
            <value>1</value>
            <ruleList>
                <!-- ... -->
            </ruleList>
        </registrySet>
    </postInstallationActionList>
    <postUninstallationActionList>
        <registrySet>
            <key>HKEY_LOCAL_MACHINE\\SOFTWARE\\${project.vendor}\\${project.fullName}</key>
            <name>DBSetup</name>
            <type>REG_SZ</type>
            <value>1</value>
            <ruleList>
                <!-- ... -->
            </ruleList>
        </registrySet>
    </postUninstallationActionList>
    

    If the number of keys is very small, it may be easier to simply add the actions twice. If the number of keys is quite large, it is also possible to create a function that creates the registry keys - such as:

        <project>
        <!-- ... -->
        <functionDefinitionList>
            <actionDefinition>
                <name>createAdditionalRegistryKeys</name>
                <actionList>
                    <registrySet>
                        <key>HKEY_LOCAL_MACHINE\\SOFTWARE\\${project.vendor}\\${project.fullName}</key>
                        <name>DBSetup</name>
                        <type>REG_DWORD</type>
                        <value>1</value>
                    </registrySet>
                    <registrySet>
                        <key>HKEY_LOCAL_MACHINE\\SOFTWARE\\${project.vendor}\\${project.fullName}</key>
                        <name>DBPath</name>
                        <type>REG_SZ</type>
                        <value>${dbpath}</value>
                    </registrySet>
                </actionList>
                <parameterList>
                    <stringParameter name="dbpath" default="" />
                </parameterList>
            </actionDefinition>
        </functionDefinitionList>
        <preInstallationActionList>
            <createAdditionalRegistryKeys>
                <dbpath>${installdir}/db</dbpath>
            </createAdditionalRegistryKeys>
        </preInstallationActionList>
        <postUninstallationActionList>
            <createAdditionalRegistryKeys>
                <dbpath>${installdir}/db</dbpath>
            </createAdditionalRegistryKeys>
        </postUninstallationActionList>
    </project>
    

    Please note that functions require passing parameters and have no access to variables - i.e. accessing ${installdir} directly would not work in a function, unless it is explicitly passed or <globalVariables names="installdir" /> action is used in the function to have it access variables from global scope.

Please sign in to leave a comment.