title: Unable to modify .ini file in c:\windows directory
body: <p>I'm writing a C# Windows application to update a .ini file for a legacy application. I don't have the source for the legacy application, so I cannot modify it.</p>
  
  <p>The legacy application stores settings in a INI file in C:\Windows. This location cannot be changed. </p>
  
  <p>To modify the INI settings I've been using these Windows functions:</p>
  
  <pre><code>[DllImport("kernel32.dll", EntryPoint = "GetPrivateProfileString")]
  private static extern int GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
  
  [DllImport("kernel32.dll", EntryPoint = "WritePrivateProfileString")]
  private static extern bool WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFileName);
  </code></pre>
  
  <p>The above functions don't seem to modify the INI file, however subsequent calls to "GetPrivateProfileString" show the correct/modified values.</p>
  
  <p>Additionally I've even tried writing directly to the INI file using System.IO classes. This didn't seem to modify the INI file.</p>
  
  <p>If I try to copy the file to the application's directory then write the INI settings, the correct values are written. If I then try to copy this modified file back to C:\Windows the original INI file doesn't seem get modified.</p>
  
  <p>It seems like there's some type of INI file cache happening at the OS level?</p>
  
  <p>If I manually edit the INI file using a text editor the INI file is updated.</p>
  
  <p>As suggested on other forums I've also tried this code after writing the INI setting:</p>
  
  <pre><code>WritePrivateProfileString(null, null, null, filename);
  </code></pre>
  
  <p>My problem is that the legacy app doesn't pick up the INI file changes (even after restarting the legacy app).</p>