如何以编程方式更改 Active Directory 密码
我有一组将要创建的测试帐户,但这些帐户将设置为要求在首次登录时更改密码。 我想用 C# 编写一个程序来检查测试帐户并更改密码。
I have a set of test accounts that are going to be created but the accounts will be setup to require password change on the first login. I want to write a program in C# to go through the test accounts and change the passwords.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以使用 UserPrincipal 类' SetPassword 方法,前提是您有足够的权限,一旦找到正确的 UserPrincipal 对象。 使用 FindByIdentity 查找有问题的主体对象。
You can use the UserPrincipal class' SetPassword method, provided you have enough privileges, once you've found the correct UserPrincipal object. Use FindByIdentity to look up the principal object in question.
这是一个很棒的 Active Directory 编程快速参考:
Howto:(几乎)通过 C# 实现 Active Directory 中的所有内容
请参阅末尾附近的密码重置代码。
Here's a great Active Directory programming quick reference:
Howto: (Almost) Everything In Active Directory via C#
See the password reset code near the end.
试试这个代码。 这个对我有用,
Try this code. It works for me,
这是解决方案:
Here is the solution:
可以使用 .NET Framework 2.0 为域帐户设置新密码。
请参阅下面的工作代码:
检查 uEntry 处的参数非常重要,代码将在当前线程安全上下文下运行,除非指定 null 值
It is possible to set a new password to a domain account, by using .NET Framework 2.0.
See working code bellow:
it is very importan to check the parameters at uEntry, the code will run under the current thread security context, unless the null values are specified
如果在同一天早些时候完成设置密码以给用户提供新密码,我在使用更改密码的 Windows 应用程序中遇到问题。 发生这种情况是因为我们的域有密码最短使用期限的政策。 解决方案是在使用“设置密码”时还将“密码更改日期”设置为 0(空),以便用户随后可以在同一天更改其密码。
I had an issue in a windows application using Change Password if Set Password was done earlier that same day to give the user a new password. This happened because our domain has a policy of a minimum password age. The solution was to also set the Password Change date to 0 (empty) when using Set Password so the user can subsequently change their password the same day.