Click here to Skip to main content
15,891,763 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi I got an issue when I user Directory Service to change passwod.
here is the code:
C#
try
           {
               string conString = string.Format("WinNT://{0}/{1}",ServerName, UserName);
               DirectoryEntry de = new DirectoryEntry(conString);
               de.Invoke("ChangePassword", new object[] {PasswordCurrent, PasswordNew });
               de.CommitChanges();

               return String.Empty;
           }
           catch (Exception ex)
           {
               return ex.InnerException.Message;
           }

The problem is that I really used the right old passowd to change password,but It throw an Exception with message "The specified network password is not corrent."

BTW,My PC is in a domain,and I'm trying to change the password of local administrator with this code. the logged account is an domain account in Local Administrators Group.

I googled this message,and have ever set Local security and modified LSA node in registry by googled solutions,but with no lucky for this issue.

then I tried "SetPassword" instead.It Work OK. but I don't know why.
I doubt there is some tricks for the use of these two methods.

for your reference:
http://msmvps.com/blogs/alunj/archive/2006/11/07/ChangePassword-versus-SetPassword.aspx[^]
I did't got the reason why the method Changepassord didn't work.

Thanks, Any reply is appreciated.
Posted

1 solution

Use the Shell or its equivalent and execute this :

net user "[username]" *

Replace [username] with the actual username.

Then use SendKeys.SendWait to send the new password, send a return, password again and return.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900