Search code examples
wixwindows-installercustom-actiondelete-file

Deleting files and directories before installation of MSI


Our product was installed via InstallShield Setup over the years. I changed the installation to MSI (WiX) this year. Now the MSI should clean up the directory, which remains the same.

One custom action in the MSI I implemented to start the uninstallation of the old product:

 <CustomAction Id="UninstallIS" Property="QtExecCA" Value="&quot;[WindowsFolder]IsUn0407.exe&quot; -f &quot;[ProgramFilesFolder]\company\product\Uninst.isu&quot;" Execute="deferred" />
 <CustomAction Id="QtExecCA" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="ignore" Impersonate="no" />

After the removal of the old product there are temporary files and some subdirectories that are different from client to client and are unknown to the InstallShield Setup, so I would try to delete them via the MSI.

Keeping the UAC in mind, I think that I can't use command-line commands to do this also the 'Remove File Table' is not useful here (to much unknown files and many directories).

What is a possible way to do this?

Thank You for any help!


Solution

  • You can use a Deferred custom action which has Impersonate flag set to "no". This way it will run under the local system account with full privileges.

    The custom action can use custom code (for example an EXE or DLL) or a command line.

    Please note that deferred custom actions can be scheduled only after InstallInitialize action in InstallExecuteSequence.

    As a side-note, make sure you thoroughly test it. Deleting files from the target machine is very dangerous. You never know what you may end up deleting.