[wix-users] Unable to delete files from install dir using Custom action

Shir Borer shir.b at lls-ltd.com
Thu Nov 11 13:12:09 PST 2021


Hello all! I'm trying to create a custom action which will delete files in the installation folder.
I first tried using a "cmd.exe" action:

<CustomAction Id="InstallService" Return="check" Impersonate="no" Execute="deferred" Directory="INSTALLFOLDER" ExeCommand='cmd.exe /C del /s /q "[INSTALLFOLDER]"'/>
<InstallExecuteSequence>
      <Custom Action="InstallService" Before ="InstallFiles">NOT REMOVE</Custom>
</InstallExecuteSequence>

This worked for me but failed on some computers with:
Error 1721. There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support personnel or package vendor
Trying different impersonate and Execute value did not help.

Then I tried to create a DLL custom action. in which I do:

            //string installDir = session["installDir"];
            string installDir = session.CustomActionData["installDir"];
            session.Log($"install: {installDir}");

            System.IO.DirectoryInfo di = new DirectoryInfo(installDir);

            foreach (FileInfo file in di.GetFiles())
            { ...

​This also fails, and although the log prints the correct path:
install: C:\Users\Shir\AppData\Local\INSTALL\
I get error:
Could not find a part of the path 'C:\WINDOWS\Installer\MSIF072.tmp-\C:\Users\Shir\AppData\Local\INSTALL\'

Why is this tmp directory prepended to my path?
I would appreciate any help in finding out the proper way to delete files from the installation folder.

Thanks in advance
                              -Shir.


More information about the wix-users mailing list