Search code examples
wixwix3.5wix3wix3.6

How to change the permissions of the file that is already created using wix installer


My requirement is, When installing the older installer package the file (Config.txt) is getting created with system permissions in the ProgramData folder. And from the code, we are not able to remove the file without admin permissions. For this reason, when installing the newer installer i wanted to changes the permissions of the file so that from the code i can remove that file.

I am new to Wix installer, i am trying it like as shown below. But it is not working.

Below is the code snippet:

<Property Id="PROGRAMDATA" Value="C:\ProgramData\TestApp\Config"/>
<Property Id="APP_SEARCH">
            <DirectorySearch Id="APP_DIR" value="[PROGRAMDATA]" Depth="0">
                <FileSearch Id="FILE_SEARCH" Name="Config.txt" />
            </DirectorySearch>
</Property>

<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="CommonAppDataFolder" ShortSourceName="Common~1" SourceName="CommonAppData">
<Directory Id="NEWINSTALLDIR">   
<Directory Id="APPCORE" Name="APPCore">
    <Component Id="APP" Guid="{681F6F86-00D7-41A3-8DBB-44AFE9880941}" KeyPath="yes">
                                
        <File Id="FILE_SEARCH" Name="Config.txt" Value="[PROGRAMDATA]" KeyPath="no">
            <Permission GenericAll="yes" User="Everyone" Delete="yes"/>
        </File>
        <RemoveFile Id="FileKey3" Directory="APPCORE" Name="*" On="uninstall" />
                                
    </Component>
</Directory>
</Directory>
</Directory>
</Directory>

Solution

  • Changing file permissions using Permission or PermissionEx only works with files that are created/installed by the very same setup.

    In your case utilizing cacls will solve the problem.

    <!-- Edit file permissions -->
    <CustomAction Id='UnlockFile' Directory='TARGETDIR' ExeCommand='echo Y | cacls "[MyFilePathProperty]" /C /E /G Users:W' Return='asyncNoWait' Execute='deferred'/>
    <InstallExecuteSequence>
        <Custom Action='UnlockFile' Before='InstallFinalize'>NOT REMOVE</Custom>
    </InstallExecuteSequence>