title: Access Denied When Attempting To Edit A File ProgramFiles
body: <p>I am trying to edit a config file in the program files. These config files are used by Windows services. Here's the details:</p>
  
  <ul>
  <li>I can't change the location of the file to be edited</li>
  <li>UAC is OFF</li>
  <li>Just in case, the app.manifest has been edited so it runs as admin</li>
  </ul>
  
  <p>Here's the code:</p>
  
  <pre><code>public void UpdateDNSNameInConfigFile(string v, ConfigFileOption cf)
      {
          string ConfigFilePath = Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + @"\&lt;redacted&gt;\&lt;redacted&gt;";
          string ConfigFileContents = string.Empty;
          string DNSName = v.Replace("/ucf:", ""); //Remove the command line arg from the value
  
          switch (cf)
          {
              case ConfigFileOption.CobanSystem:
                  ConfigFilePath = ConfigFilePath + @"\&lt;redacted&gt;.&lt;redacted&gt;System";
                  break;
              case ConfigFileOption.Agent_AVL:
                  ConfigFilePath = ConfigFilePath + @"\&lt;redacted&gt;.Agent.AVL";
                  break;
              case ConfigFileOption.Agent_DB:
                  ConfigFilePath = ConfigFilePath + @"\&lt;redacted&gt;.Agent.DB";
                  break;
              case ConfigFileOption.Agent_DVD:
                  ConfigFilePath = ConfigFilePath + @"\&lt;redacted&gt;.Agent.DVD";
                  break;
              case ConfigFileOption.Agent_FileAgent:
                  ConfigFilePath = ConfigFilePath + @"\&lt;redacted&gt;.Agent.FileAgent";
                  break;
              case ConfigFileOption.Agent_Log:
                  ConfigFilePath = ConfigFilePath + @"\&lt;redacted&gt;.Agent.Log";
                  break;
              case ConfigFileOption.Agent_Streaming:
                  ConfigFilePath = ConfigFilePath + @"\&lt;redacted&gt;.Agent.Streaming";
                  break;
              case ConfigFileOption.Agent_Listener:
                  throw new NotImplementedException();
              case ConfigFileOption.Agent_InCar:
                  throw new NotImplementedException();
              case ConfigFileOption.Agent_Tape:
                  throw new NotImplementedException();
          }
  
          ConfigFileContents = File.ReadAllText(ConfigFilePath);
          ConfigFileContents = ConfigFileContents.Replace("&lt;redacted&gt;", v);
          File.WriteAllText(ConfigFilePath, ConfigFileContents);
      }
  </code></pre>
  
  <p>Any ideas?</p>