0

In the Product.wxs file I used for my installer, I have a feature that creates some folders in ProgramData and adds some files to those

<Feature Id="IOFilesFeature" Title="Settings and IO Files" Level="1">
      <Feature Id="Languages" Title="Languages" Level="2">
        <Feature Id="Languages_UK" Title="English" Level="3">
          <ComponentGroupRef Id="ProgramData_MFR_PRD_Languages_UK" />
        </Feature>
      </Feature>
      <Feature Id="OpsPC1" Title="Operator PC 1" Level="2">
        <Feature Id="OpsPC1_Settings" Title="Settings" Level="3">
          <ComponentGroupRef Id="ProgramData_MFR_PRD_Settings_Ops1" />
        </Feature>
        <Feature Id="OpsPC1_IO" Title="IO" Level="1">
          <ComponentGroupRef Id="ProgramData_MFR_PRD_IO_Ops1" />
        </Feature>
      </Feature>
</Feature>
<Fragment>
      <Directory Id="CommonAppDataFolder" Name="ProgramData">                                   
        <Directory Id="PD_MFR" Name="CompanyName">                                                  
          <Directory Id="PD_MFR_PRD" Name="ProductName">                                            
            <Directory Id="PD_MFR_PRD_Languages" Name="Languages" />                        
            <Directory Id="PD_MFR_PRD_Settings" Name="Settings" />             
            <Directory Id="PD_MFR_PRD_IO" Name="IO" />               
          </Directory>
        </Directory>
      </Directory> 
</Fragment>

Each file is similar to this:

<Fragment>
    <ComponentGroup Id="ProgramData_MFR_PRD_IO_Ops1" Directory="PD_MFR_PRD_IO">
      <Component Id="FileID" Guid="2be6ba39-9496-4985-8317-5bd0b3f88f95">
        <File Id="FileID" Name="FileName" Source="SourceLocation" />
      </Component>
    </ComponentGroup>
  </Fragment>

I noticed after using the installer that the files could not be edited by the program. Manual edits would show only in windows explorer. When I looked at the file contents after reading them from the below code the contents would not update to what I had manually changed.

    public static string ReadFile(string fullPath)
    {
      string rv = "";
      try
      {
        if (File.Exists(fullPath))
        {
          FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
          if (fs.CanRead)
            using (StreamReader sr = new StreamReader(fs))
              rv = sr.ReadToEnd();
        }
      }
      catch (Exception ex)
      {
        ex.WriteToFile();
      }
      return rv;
    } 

I deleted the CompanyName folder from within ProgramData to see if it would allow the program to recreate the files and the program could still read the file. Windows explorer would show that the folder did not exist.

Do you know what could be causing the files to "ghost" this way?

  • I searched for one of the specific files in the folder and found that the files had been recreated in C:\Users\EdwardMo\AppData\Local\VirtualStore\ProgramData\ rather than C:\ProgramData. My laptop has been upgraded to windows 10 since i first made this installer, I dont think this was happening before then. These files need to be common between Users on the PC, is there a way of making the installer use C:\ProgramData instead of the Virtual Store? – Edward Morris Apr 02 '20 at 11:13

1 Answers1

0

Once I found out it was writing to the virtual store I found this:

Privileges/owner issue when writing in C:\ProgramData\

Which said that the sub directory must be given a permissive ACL by the installation program.

I followed Wix: How to set permissions for folder and all sub folders to apply this, and now the application is working as expected again.