title: Programmatically add Local User to a Local Group
body: <p>I am doing a C# application targeting WinXP, Vista, and 7 Operating Systems.</p>
  
  <p>One feature is, I can Add, Remove, Modify the Group set to a user programmatically.</p>
  
  <p>Can I ask for help how to make this happen?</p>
  
  <p>Will it be possible to do this in WMI? My codes mainly using WMI to get the users..</p>
  
  <hr>
  
  <p>Currently am using Windows7</p>
  
  <p>I am trying to test this code</p>
  
  <pre><code>DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName + ",Computer");
  localMachine.Properties["member"].Add("Chevi");
  localMachine.CommitChanges();
  localMachine.Close();
  </code></pre>
  
  <p>and it's spitting this error</p>
  
  <blockquote>
    <p>The directory property cannot be found in the cache.</p>
  </blockquote>
  
  <p>I tried enumerating the Property collection and I got this</p>
  
  <pre><code>OperatingSystem
  
  OperatingSystemVersion
  
  Owner
  
  Division
  
  ProcessorCount
  
  Processor
  
  Name
  </code></pre>