views:

173

answers:

3

Hello,

I am relatively new to WiX. It is a great tool, but I still need some time to learn it better. I have encountered a problem with registration and unregistration of a COM component. I have created installers for two applications, lets call them A and B. Both are using the same COM component. I have used the heat tool, as recommended. When installing A or B, the component is registered without any problems.

But when I install A and B, then remove A (with Add/Remove programs) the COM class gets unregistered and B cannot use it anymore. Is there a clean solution to prevent this from happening? I would like to unregister the COM when BOTH A and B are uninstalled.

Any help would be appreciated,

Best regards, madbadger

EDIT: Thanks for your responses. I set the GUID to the same value in the both installers and now the registry keys are being removed properly, that is when the last program is removed from system.
Hovewer, the problem persists for one reason. I have checked the registry under HKEY_CLASSES_ROOT/CLSID/[appropriate COM GUID]. This is what happens:
- I install A and the path to COM is set to [path to A/component.dll]
- I install B and the path to COM is set to [path to B/component.dll]
- I remove B and the path to COM remains [path to B/component.dll]
- Now A cannot access the COM component althrough it is registered, because [path to B/component.dll] does not exist anymore

Now I assume it is obligatory to put the COM component in the same directory for both applications. Is Windows Installer not able to revert to the old path, or is it something I am missing?

+3  A: 

The windows installer will do this for you, but only if your COM component has the same GUID across both A and B, (and the dll's are installed in the same place by both applications.)

Windows installer works by reference-counting each component (across the whole system). Components are identified by their GUID's.

If the COM component has the same GUID, what happens is this:

  • Install A: Component refcount goes from 0->1, windows installer registers it
  • Install B: Component refcount goes from 1->2, nothing happens
  • Uninstall A: Component refcount goes from 2->1, nothing happens
  • Uninstall B: Component refcount goes from 1->0, windows installer unregisters it

If it doesn't have the same GUID, what happens is this

  • Install A: Component A refcount goes from 0->1, windows installer registers it
  • Install B: Component B refcount goes from 0->1, windows installer registers it, overwriting registry entries from component A.
  • Uninstall A: Component A refcount goes from 1->0, windows installer unregisters it, deleting registry entries.
    -- It appears as though this is the situation you're in
  • Uninstall B: Component B refcount goes from 1->0, windows installer unregisters it, deleting registry entries (but they're already deleted)

Edit Uplifted from comments:

As well as the GUID, each component also has a "Key Path". If the component contains one or more files, you should set which file is the "Key" file using KeyPath="foo.dll". If the component contains one or more registry entries, it's similar.

When checking if something is installed, the windows installer will check the GUID, read the key path, then check the file at the key path (this is how it figures out what version things are, amongst other things), so if 2 components have the same GUID, they must also have the same key path, which must resolve to the same place in the file system when the product is installed.

This is a longwinded way of saying both installers must put the shared files in the same place. As for where to put them, System32 is NOT a good place.

I'd suggest somewhere under the common files folder (usually Program Files\Common Files\YourCompanyName). You'd enter this in Wix like so: Directory="[CommonFilesFolder]\YourCompanyName"

Orion Edwards
Should I put the COM component in one location for both installers? Is the system32 folder a good place for it?
madbadger
Yeah, you have to put it in the same location. (The windows installer identifies with both the GUID and the file/registry path). System32 is NOT a good place. I'd suggest somewhere under the common files folder (usually `Program Files\Common Files\YourCompanyName`). You'd enter this in Wix like so: `Directory="[CommonFilesFolder]\YourCompanyName"`
Orion Edwards
Thanks a lot for explaining this so well!
madbadger
No worries. One other tip while I'm at it - try and put each file in it's own component. The windows installer will only ever add and remove entire components, so if you have a component with 3 files in it, and you want to remove one during an upgrade... you're screwed. One-component-per-file solves this.
Orion Edwards
+1  A: 

In your Component tag, are you using the same Guid in each installer?

richb
A: 

You should wrap this common component in merge module and reference it from both your apps.

This will automagically let the shared dlls refcounting do its job on uninstall.

wqw