title: UnauthorizedAccessException: Access to the path is denied
body: <p>As a part of service installer using <strong>Wix 3.XX</strong>, we have been trying to encrypt the connection string.
  After visiting couple of option on Stackoverflow and some other communities, we have opted to do it in three parts.</p>
  
  <ol>
  <li>Installer that installs the service in the first part</li>
  <li>At the end of installation it invokes the small executable that picks the location of connection of existing config, encrypts the connection string inside the installation folder and save that config.</li>
  <li>A <code>.bat</code> file that clears out the executable for the encryption (basically leaving no traces behind)</li>
  </ol>
  
  <p>All three parts works well with co-ordination, but the encryption executable fails when I try to install that in "<strong>Program Files</strong>" or "<strong>Program Files (x86)</strong>" using non-elevated permission (non-admin mode). </p>
  
  <p>Debugging that has given me traces which means that Installer is unauthorized for any such processes.</p>
  
  <p>Here is the code snippet that does it:</p>
  
  <pre><code>1. var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = configPath };
  2. var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
  3. var section = configuration.GetSection(sectionToEncrypt);
  4. section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
  5. section.SectionInformation.ForceSave = true;
  6. configuration.Save(ConfigurationSaveMode.Modified);
  </code></pre>
  
  <p>Reaching at line 6 it returns me with an error:</p>
  
  <pre><code>System.Configuration.ConfigurationErrorsException
  HResult=0x80131902
  Inner Exception 1: 
  UnauthorizedAccessException: 
  Access to the path 'C:\Program Files (x86)\&lt;AppDirectory&gt;\5tkbxj1v.tmp' is denied.
  </code></pre>
  
  <p>Any inputs for this will be gracious.</p>
  
  <p>Thanks in advance for the help!</p>