We have distributed an old version of our wix installer with some files installed as Permanent="yes" components. But now we want to ask the user for retain or delete those files on unistall. This files are located on Program Files folder. We get on DELETE_ALL the user response. This is:
<InstallExecuteSequence>
<!-- more custom actions -->
<Custom Action="DeleteFiles" Before="InstallFinalize">(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL") AND (NOT (DELETE_ALL=0))</Custom>
</InstallExecuteSequence>
<CustomAction Id="DeleteFiles" ExeCommand='Company.CustomActions.ExeActions.exe' Directory="INSTALLDIR" Return="check" Impersonate="yes" Execute="immediate" />
Company.CustomActions.ExeActions.exe is a simple console application than delete those files on C:\Program Files (x86)\Company\Program1 with a manifest with
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
On .msi execution we get this lines:
MSI (s) (20:88) [15:16:19:130]: MSI_LUA: Elevation required to install product, will prompt for credentials
MSI (s) (20:88) [15:16:21:798]: MSI_LUA: Credential Request return = 0x0
MSI (s) (20:88) [15:16:21:798]: MSI_LUA: Elevated credential consent provided. Install will run elevated
Or if we launch it from Administrator cmd.exe:
MSI (c) (24:F8) [12:35:32:530]: MSI_LUA: Setting AdminUser property to 1 because this is the client or the user has already permitted elevation
We try to set for our DeleteFiles custom action set diferent values for Impersonate (yes/no) and Execute (immediate/deferred) without get success on it.
Further we try to do this deletion by a component with RemoveFiles or on a CustomAction written in c# marked with a CustomActionAttribute like others we use. Also no success.
[CustomAction]
public static ActionResult DeleteAll(Session session) { /*...*/ }
Or calling from CustomAction to another method:
[PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")]
private static void DeleteFiles() { /*...*/ }
We get an expcetion:
Request for principal permission failed.
at System.Security.Permissions.PrincipalPermission.ThrowSecurityException()
at System.Security.Permissions.PrincipalPermission.Demand()
at System.Security.PermissionSet.DemandNonCAS()
at Company.CustomActions.DeleteFiles(Session session)
at Company.CustomActions.DeleteALL(Session session)
It's possible to implement a feature to delete permanent files installed in previous version on demand? Any idea?