title: Use admin privilege on WIX custom action
body: <hr>
  
  <p><strong>Glytzhkof</strong>: <em>This question relates to a common problem for new MSI users, the belief that one needs a custom action for something MSI supports natively by a feature they are unaware of.</em></p>
  
  <p>In this case the <strong>IniFile table</strong> in MSI that allows <strong>merging</strong>, <strong>rollback</strong> and <strong>updating</strong> of shared Ini files on the system. All updates to Ini files should be performed via this table since you get a lot of features for free and you will be in line with all MSI guidelines.</p>
  
  <p>Always avoid custom actions if there is a way to achive the same effect by native features.</p>
  
  <hr>
  
  <p>I have a c# customaction on my WIX msi.</p>
  
  <p>When msi start require admin account and all works fine excepted for my customaction, it can't write inside programdata folder.</p>
  
  <p>I have set <code>impersonate="no"</code> according to wix reference:</p>
  
  <blockquote>
    <p>This attribute specifies whether the Windows Installer, which executes as LocalSystem, should impersonate the user context of the installing user when executing this custom action. Typically the value should be 'yes', except when the custom action needs elevated privileges to apply changes to the machine.</p>
  </blockquote>
  
  <p>But does not works.</p>
  
  <p>This is my custom action configuration:</p>
  
  <pre><code>&lt;CustomAction 
  Id="MyCustomActionCA" 
  BinaryKey="mycustomactionDLL" 
  DllEntry="MyCustomAction" 
  Execute="immediate" Return="check" Impersonate="no" /&gt;
  
  &lt;InstallUISequence&gt;
    &lt;Custom Action="MyCustomActionCA" After="CustomDialog1"&gt;NOT Installed&lt;/Custom&gt;
  &lt;/InstallUISequence&gt;
  </code></pre>
  
  <p><code>MyCustomAction</code> is launched after <code>CustomDialog1</code> is closed, and this is OK, my code run fine but in <code>MyCustomAction</code> i have a line of code like this:</p>
  
  <pre><code>File.WriteAllText(mypath, mycontent);
  </code></pre>
  
  <p><code>mypath</code> refers to <code>ProgramData</code> folder and throw an exception becouse user can't write inside it.</p>