Jacmelchery
Posts: 6
Joined: Wed May 11, 2016 12:00 am

Conditional Removing Folder During Uninstall

Sun Sep 05, 2021 5:07 pm

I am trying to find out how to make this work so far, I can’t find anything that will work for me.
I have a plug-in that will be used by 2 programs let say A and B

1. I have 2 Installers, one for A and one for B
2. They will be installed in the Plug-in folder of the corresponding Program A or B
3. They will both have the same service that will be added during installation of A or B
4. They will both use the same folder for Data folder that will be placed inside the Common folder path.

I made both Installs but each one removes the folder that is placed inside the common folder. I am trying to find a way to.

1. Skip over the installation of the service if was installed by either one of them
2. To remove the service during uninstall only if only one of the plug-ins installed is present i.e., Keep the service if found A is present when
uninstalling B or B is present when uninstalling A.
3. The same for the Folder inside the Common folder. It will be removed if only one of them is present during the uninstallation. Keep the folder if A is
present when uninstalling B or B is present when uninstalling A.

Thank you. Any help would be appreciated!

Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Re: Conditional Removing Folder During Uninstall

Mon Sep 06, 2021 2:35 pm

Hello,

Please allow me to address your points:
1. Skip over the installation of the service if was installed by either one of them
There are two ways of achieving this:

1. You can have a predefined "Detect Service" custom action that will detect whether the service is running and then condition the component of your service (in "Organization" page) based on the result of the custom action.

However, considering the second request as well, I would say the best method here is:

2. Make the component of your service a shared component. More information about "Shared Components" can be found in the following articles:

Component Properties

About Shared Components (Microsoft's article)

Windows Installer Components (Microsoft's article)

Please note that there are some rules that need to be respected, so I would suggest thoroughly reading the articles I have provided above.
2. To remove the service during uninstall only if only one of the plug-ins installed is present i.e., Keep the service if found A is present when
uninstalling B or B is present when uninstalling A.
By having the component of your service shared between setup A and B, this will be fulfilled by default.

Your component will basically have a ref count that will be increased upon installing the second product (e.g. from 1 to 2) and the service will only be removed when the ref count reaches 0. With that being said, when uninstalling the second product, the ref count will be set from 2 to 1 and when uninstalling the first product, the ref count will be set from 1 to 0, resulting in the uninstall of the service.

The same principle can be applied to your folder as well.

Hope this will help!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”