2

I am using WIX for creating the installer of my application. During uninstalling the application, I want to call a function in a DLL file before the uninstaller deletes the files which the DLL file is part of them. I checked other related post like this post to proceed.

I created a CustomAction as follows:

<CustomAction Id="UnRegister" 
              FileKey="mydll.dll" 
              DllEntry="cleanup" 
              Execute="immediate" 
              Return="ignore"/>

and then the InstallExecuteSequence tag:

<InstallExecuteSequence>
    <Custom Action="UnRegister" After="InstallInitialize">Installed AND NOT UPGRADINGPRODUCTCODE</Custom>
</InstallExecuteSequence>

The problem is when I try to uninstall the application, the files are removed first and then the installer calls the cleanup() function in DLL. After the error the uninstall rolls back and fails.

How can I configure the WIX installer so that it calls the function first and then delete the files during uninstall?

Thanks

Community
  • 1
  • 1
Ali
  • 133
  • 4
  • 12
  • the files are removed after the immediate actions get executed, so the custom action should run when the files are on the machine. Can you post a verbose log of the uninstall routine, to see exactly what triggers the file deletion? – Bogdan Mitrache Jan 21 '14 at 07:28
  • The log: Error 1723. There is a problem with this Windows Installer package. A DLL required for this install to complete could not be run. Contact your support personnel or package vendor. Action Register, entry: AddInfo, library: C:\Program Files (x86)\testApp\mydll.dll. But this log shows it wants to execute the function which I used for installing. I have a similar CustomAction named "Register" : – Ali Jan 21 '14 at 15:03
  • so your custom action runs, but it fails? If so, this is most likely due to lack of admin privileges, to have them set the custom action t be executed as deferred with no impersonation, not immediate. – Bogdan Mitrache Jan 21 '14 at 15:06
  • That CustomAction is not the same one for uninstall. I use it for the installation – Ali Jan 21 '14 at 15:08
  • Also that specific custom action I got the error message for is not impersonated and executed as deferred. – Ali Jan 21 '14 at 15:11
  • In your Custom Action... use Before="RemoveFiles" – Rudy Hinojosa Aug 17 '22 at 01:38

2 Answers2

3

Thanks Bogdan. According to the log the problem was that the installer was trying to execute the CustomAction that I wanted to be run only on install time. For this, I should have added "NOT Installed" to the custom action which was supposed to run only during the install. like the following:

<Custom Action="Register" Before="InstallFinalize">NOT Installed</Custom>
Ali
  • 133
  • 4
  • 12
0

This is more a comment, since you have solved your specific problem...

You should separate out install logic from application libraries. Any custom action action you run should be implemented in files that are not installed themselves. One reason is that the files might be missing causing the uninstallation to fail.

It seems that you are using some sort of self-registration mechanism. This is an anti-pattern that Windows Installer was designed to avoid. For registry entries, you can use WiX's registry entry declaration to create and remove registry entry. The same goes for file and folders that were created by the application.

However, it is not reasonable for a machine to wiped clean upon uninstallation. There is a lot of grey area for what should be removed and what should be left. At one end are the application binaries (should be gone); At the other end are documents created by user via the application. Settings that might have been personally selected by the user are amongst many other things in the middle (they could be kept for future use after re-installation).

Tom Blodget
  • 20,260
  • 3
  • 39
  • 72