0

I have a java desktop application which is using WIX to install the application. At install WIX is creating a folder located in the {...}/AppData/Local folder. The application is then populating this folder with subfolders and files during execution of the application.

We noticed that at uninstall of the application this folder is not removed (if it is populated, if it is empty it is removed via the RemoveFolder elelemt) which leads to unpleasantries.

Reasearch into the matter shows that the RemoveFolder element can only remove empty folders, ie. without subfolders and files. For solving the issue I came up with the solution of executing a batch file with code for removing the whole folder, including sub folders and files, via a Custom Action. I thought of placing this file in the installation path of the application, which is not the same as where the folder I want to remove is placed.

After turning on logging for installing/uninstalling the application I find that this custom action is not executedc in the correct order, ie. it is executed after the installation folder is removed and thereby the batch file is never run.

Here is my WIX InstallExecuteSequence:

  <InstallExecuteSequence>

     <Custom Action='RemoveAlelionFolder' After="InstallFiles">
         Installed AND NOT UPGRADINGPRODUCTCODE
     </Custom>
      <RemoveExistingProducts After="InstallValidate"/>

  </InstallExecuteSequence>

  <CustomAction Id='RemoveAlelionFolder' ExeCommand='[INSTALLDIR]remove.bat' Directory="INSTALLDIR" Execute="deferred" Return='asyncNoWait' />

Here are parts of the install/uninstall log file:

Action ended 15:20:21: RemoveShortcuts. Return value 1.
Action start 15:20:21: RemoveFiles.
      MSI (s) (8C:BC) [15:20:21:111]: Counted 9 foreign folders to be removed.
MSI (s) (8C:BC) [15:20:21:111]: Removing foreign folder: C:\Users\Public\Desktop\
MSI (s) (8C:BC) [15:20:21:111]: Removing foreign folder: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Company\
MSI (s) (8C:BC) [15:20:21:111]: Removing foreign folder: C:\Users\{username}\AppData\Local\Company\ **<-- This is not working if folder contains files**
MSI (s) (8C:BC) [15:20:21:111]: Removing foreign folder: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Company\
MSI (s) (8C:BC){Removing a lot of folders here}
MSI (s) (8C:BC) [15:20:21:112]: Doing action: RemoveFolders
MSI (s) (8C:BC) [15:20:21:112]: Note: 1: 2205 2:  3: ActionText 
Action ended 15:20:21: RemoveFiles. Return value 1.
Action start 15:20:21: RemoveFolders.
MSI (s) (8C:BC) [15:20:21:113]: Doing action: CreateFolders
MSI (s) (8C:BC) [15:20:21:113]: Note: 1: 2205 2:  3: ActionText 
Action ended 15:20:21: RemoveFolders. Return value 1.
Action start 15:20:21: CreateFolders.
MSI (s) (8C:BC) [15:20:21:114]: Doing action: InstallFiles
MSI (s) (8C:BC) [15:20:21:114]: Note: 1: 2205 2:  3: ActionText 
Action ended 15:20:21: CreateFolders. Return value 1.
MSI (s) (8C:BC) 
MSI (s) (8C:BC) [15:20:21:118]: Note: 1: 2205 2:  3: Patch 
MSI (s) (8C:BC) [15:20:21:118]: Note: 1: 2228 2:  3: Patch 4: SELECT `Patch`.`File_`, `Patch`.`Header`, `Patch`.`Attributes`, `Patch`.`Sequence`, `Patch`.`StreamRef_` FROM `Patch` WHERE `Patch`.`File_` = ? AND `Patch`.`#_MsiActive`=? ORDER BY `Patch`.`Sequence` 
MSI (s) (8C:BC) [15:20:21:118]: Note: 1: 2205 2:  3: MsiSFCBypass 
MSI (s) (8C:BC) [15:20:21:118]: Note: 1: 2228 2:  3: MsiSFCBypass 4: SELECT `File_` FROM `MsiSFCBypass` WHERE `File_` = ? 
MSI (s) (8C:BC) [15:20:21:118]: Note: 1: 2205 2:  3: MsiPatchHeaders 
MSI (s) (8C:BC) [15:20:21:118]: Note: 1: 2228 2:  3: MsiPatchHeaders 4: SELECT `Header` FROM `MsiPatchHeaders` WHERE `StreamRef` = ? 
Action start 15:20:21: InstallFiles.
MSI (s) (8C:BC) [15:20:21:118]: Doing action: RemoveAlelionFolder **<-- Here is action for removing folder w/ files**
MSI (s) (8C:BC) [15:20:21:118]: Note: 1: 2205 2:  3: ActionText 
Action ended 15:20:21: InstallFiles. Return value 1.
Action start 15:20:21: RemoveAlelionFolder.
MSI (s) (8C:BC) [15:20:21:119]: Doing action: CreateShortcuts
MSI (s) (8C:BC) [15:20:21:119]: Note: 1: 2205 2:  3: ActionText 

Some research effort: http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Removing-Folders-td703071.html Removing files when uninstalling WiX How to add a WiX custom action that happens only on uninstall (via MSI)? https://stackoverflow.com/questions/320921/how-to-add-a-wix-custom-action-that-happens-only-on-uninstall-via-msi

svenan
  • 45
  • 7

1 Answers1

1

Solved!

I had to run the Custom Action 'After='InstallInitialize' in order for it to run at the correct place in the flow of the code.

  <InstallExecuteSequence>
     <Custom Action='RemoveAlelionFolder' After="InstallInitialize">
         Installed AND NOT UPGRADINGPRODUCTCODE
     </Custom>
      <RemoveExistingProducts After="InstallValidate"/>
  </InstallExecuteSequence>
svenan
  • 45
  • 7
  • Why not just schedule the custom action `Before='RemoveFiles'`? – Brian Sutherland Dec 18 '17 at 16:28
  • Also, consider looking into RemoveFolderEx http://wixtoolset.org/documentation/manual/v3/xsd/util/removefolderex.html which basically does what you implemented as a customaction anyways but is a more 'supported' method of doing it. In the end, whatever works will be fine though – Brian Sutherland Dec 18 '17 at 16:30