Custom Action - Only uninstall if installed

1.1k Views Asked by At

I have a Windows Installer project attached to my solution, which allows the user to optionally install two components of the application (they are Windows Services) using a "Checkboxes" dialogue box which I've added to the User Interface, and then Conditions on the Custom Actions...

i.e. in Custom Actions / Install I have

Primary output from ProjectA (Active)
- Condition = PROJECTACHOSEN (i.e. the Checkbox1Property value)

Primary output from ProjectB (Active)
- Condition = PROJECTBCHOSEN (i.e. the Checkbox2Property value)

In Custom Actions / Uninstall, I've added the same two "Primary Outputs".

The problem is, if during installation the user only chose one of the two projects then the uninstaller still tries to uninstall both of services, and of course throws an error when it doesn't find the missing one, causing the uninstall to fail.

What condition can I add in Uninstall to only install the service if it's currently installed?

I've tried:

  • adding the same conditions as the Install - this doesn't remove the services at all (presumably because you're not ticking the boxes during uninstallation)
  • Condition = "Installed" which I came across elsewhere on the web. This appears to be ignored and the uninstaller still tries to uninstall both services.
2

There are 2 best solutions below

0
On BEST ANSWER

you can use ?ComponentName to check install state of a component, i used it similarly few months ago.

Ive found about it in cheat sheet from flexera here

0
On

The best solution I've managed to come up with so far is:

  1. Add a File Search "Launch Condition" for each project that checks for the existence of the .exe file that is the service, and give it a "Property" value.

  2. Use the property value as the "Condition" of the Custom Action.

This works but I'm not totally happy with it, as it's more important that the service is deleted than the exe and if the exe goes missing it won't work and the service will remain...

Edit

Even that doesn't work unless I set the Search "Depth" to at least 3 (even though the exe file is in the installation directory and the "Folder" set to [TARGETDIR]), but if I do that, the installer takes about 20 seconds just to start up - presumably because of the time it takes to search 3 levels of subdirs. But if I set to any less than that although the installer starts quickly it now doesn't seem to find the exe and doesn't uninstall the service...

Shouldn't [TARGETDIR] reflect my installation directory and therefore work with a depth of 0?