title: Force local user to change password at next login with C#
body: <p>I'm writing a function for a web app in ASP.NET where the client logs into the server machine, which is Windows authenticated against the local users on the server. The function I am writing resets the users password and emails them the new one. I do this like so:</p>
  
  <pre><code>String userPath = "WinNT://"  + Environment.MachineName + "/" + username.Text;
  DirectoryEntry de = new DirectoryEntry(userPath);
  de.Invoke("SetPassword", new object[] { password });
  </code></pre>
  
  <p>How can I also check the flag to force the user to change their password the next time they log in with the password emailed to them? I tried using pwdLastSet like so:</p>
  
  <pre><code>de.Properties["pwdLastSet"].Value = 0;
  </code></pre>
  
  <p>But this apparently only works with LDAP, not WinNT, and I am doing this locally.</p>
  
  <p>Any experts know any better than me? I have even tried looking for a way to do this through the command line so that I can just create a Process, but I haven't been able to find a way to do it that way, either.</p>