title: How to set Windows audit policies programmatically?
body: <p>I have written a program that receives WMI events. Right now I have to manually go into the security settings in order to turn on the events of interest. </p>
  
  <p><a href="https://i.stack.imgur.com/3TlAl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3TlAl.png" alt="Local Security Policy"></a></p>
  
  <p>I can do this through the Windows GUI, but would like a way to do this programmatically. </p>
  
  <p>I've looked at <code>secedit</code> and <code>auditpol</code>, but I can't seem to get their syntax correct. I either do not know which database to use, can't establish valid paths, or don't have the right permissions figured out.</p>
  
  <p>I'd be happy with help in <code>batch</code>, <code>powershell</code>, or even <code>C++</code>. How can I create a small script or app that sets the audit policies when ran? </p>
  
  <p><em>Edit 8/3/16</em></p>
  
  <p>Why can't a backup with <code>auditpol</code>?</p>
  
  <pre><code>PS E:\agent\bin&gt; auditpol /backup /file:backup.csv
  Error 0x0000000D occurred:
  The data is invalid.
  
  PS E:\agent\bin&gt; auditpol /backup /file:C\backup.csv
  Failed to open file
  Error 0x00000003 occurred:
  The system cannot find the path specified.
  
  PS E:\agent\bin&gt; auditpol /backup /file:E\backup.csv
  Failed to open file
  Error 0x00000003 occurred:
  The system cannot find the path specified.
  </code></pre>