title: Change Local user settings from within c#
body: <p>I need to write a program that will take a existing local windows user, change the "Start the following program at logon field" in their environment tab and change the password to a new password.</p>
  
  <p>I am using local users instead of AD, will System.DirectoryServices work? Also any tutorials on using System.DirectoryServices would be very helpful.</p>
  
  <p>EDIT --
  Ok, so I can find the existing user and I know how to update it. However I do not know what to put in the ???. What AD property represents "Start the following program at logon field" in their environment tab on the user settings page?</p>
  
  <pre><code>        DirectorySearcher search = new DirectorySearcher();
          search.Filter = String.Format("(SAMAccountName={0})", prams.user);
          search.PropertiesToLoad.Add("cn");
          SearchResult result = search.FindOne();
          if (result == null)
          {
              Console.Error.WriteLine("No user of name {0} in the system", prams.user);
              return -2;
          }
          DirectoryEntry entry = result.GetDirectoryEntry();
          entry.InvokeSet("???", new object[] { newProgramLognField });
  </code></pre>
  
  <p>EDIT two---
  I now know that the field I need is "Parameters" however I this term is very hard to search for in the MSDN because it is such a generic term. I think I have the correct one because when i run the code</p>
  
  <pre><code>DirectoryEntry entry = new DirectoryEntry("WinNT://testComputer/testUser");
  Console.WriteLine("connected");
  string value = (string)entry.Properties["Parameters"].Value;
  Console.WriteLine(value);
  </code></pre>
  
  <p>I get the result</p>
  
  <pre><code>P☺CtxCfgPresent????☺CtxCfgFlags1
  ????☺CtxShadow????*☻☺CtxMinEncryptionLevel? @☺CtxWorkDirectory??????????????????
  ??????????????"C☺CtxInitialProgram??????????????????????????????????????????????
  ????????????????????????????????????????????????????????????????????????????????
  ????????
  </code></pre>
  
  <p>I am guessing that InitalProgram portion is close to what I want, most likely the ??? after is is the existing path that is there but has be mucked up.</p>
  
  <p>Now the question is how do I write correctly to it?</p>
  
  <p>Edit-3
  I try changing the casting from a string to a PropertyValueCollection however that just gives me the error at run time</p>
  
  <pre><code>Unhandled Exception: System.InvalidCastException: Unable to cast object of type
  'System.String' to type 'System.DirectoryServices.PropertyValueCollection'.
  at UserUpdater.Program.Main(String[] args) in e:\Visual Studio 2008\Projects\
  UserUpdater\UserUpdater\Program.cs:line 91
  </code></pre>