设置密码更改密码. [英] Setpassword & Changepassword.
问题描述
嗨
使用目录服务更改密码时遇到问题.
这是代码:
Hi
I got an issue when I user Directory Service to change passwod.
here is the code:
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;
}
问题是我确实使用了正确的旧密码来更改密码,但是它引发异常,并显示消息指定的网络密码不正确."
顺便说一句,我的电脑在域中,我正在尝试使用此代码更改本地管理员的密码.登录的帐户是本地管理员组中的域帐户.
我搜索了此消息,并曾经通过谷歌搜索解决方案在注册表中设置了本地安全性并修改了LSA节点,但对于这个问题却不走运.
然后我尝试了"SetPassword".它工作正常.但我不知道为什么.
我怀疑使用这两种方法有一些技巧.
供您参考:
http://msmvps.com/blogs/alunj/archive/2006/11/07/ChangePassword-versus-SetPassword.aspx [ ^ ]
我没有找到方法Changepassord无法使用的原因.
谢谢,感谢您的答复.
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.
推荐答案
使用Shell或等效程序并执行以下操作:
net user "[username]" *
将[username]
替换为实际的用户名.
然后使用SendKeys.SendWait
发送新密码,发送回信,再次输入密码并返回.
Use the Shell or its equivalent and execute this :
net user "[username]" *
Replace[username]
with the actual username.
Then useSendKeys.SendWait
to send the new password, send a return, password again and return.
这篇关于设置密码更改密码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!