如何更改密码的用户帐户,通过C#代码? [英] how to change password to user account, by c# code?
本文介绍了如何更改密码的用户帐户,通过C#代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改密码的用户帐户,通过C#代码
how to change password to user account, by c# code?
推荐答案
使用Active Directory:
Using active directory:
// Connect to Active Directory and get the DirectoryEntry object.
// Note, ADPath is an Active Directory path pointing to a user. You would have created this
// path by calling a GetUser() function, which searches AD for the specified user
// and returns its DirectoryEntry object or path. See http://www.primaryobjects.com/CMS/Article61.aspx
DirectoryEntry oDE;
oDE = new DirectoryEntry(ADPath, ADUser, ADPassword, AuthenticationTypes.Secure);
try
{
// Change the password.
oDE.Invoke("ChangePassword", new object[]{strOldPassword, strNewPassword});
}
catch (Exception excep)
{
Debug.WriteLine("Error changing password. Reason: " + excep.Message);
}
在这里你有例子来改变它在本地用户帐户:
Here you have example to change it in the local user account:
http://msdn.microsoft.com / EN-US /库/ ms817839
其他替代可能正在使用的互操作性和调用非托管代码:的netapi32.dll
Other alternative could be using interoperability and call unmanaged code: netapi32.dll
的 http://msdn.microsoft.com/en-us/library/aa370650(VS.85)的.aspx
这篇关于如何更改密码的用户帐户,通过C#代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文