【问题标题】:Preventing an Active Directory user from changing his/her password using DirectoryServices防止 Active Directory 用户使用 DirectoryServices 更改他/她的密码
【发布时间】:2010-02-03 12:56:35
【问题描述】:

从脚本创建 Active Directory 用户时,我还需要设置他们不能更改密码的选项。通过管理 GUI,这很容易通过选中“用户无法更改密码”来完成。然而,以编程方式,这是另一回事。我找到了一个recipe,它涉及与 ADSI COM API 的交互,但出于技术原因,我想通过 .NET API 完成相同的操作(短版:我无法从我的脚本)。

我已尝试将上述配方转换为纯 .NET,正如在此 Python sn-p 中所见,但不幸的是它没有效果:

dir_entry = System.DirectoryServices.DirectoryEntry(ad_user)
obj_sec = dir_entry.ObjectSecurity
# Password GUID
guid = System.Guid(System.String("ab721a53-1e2f-11d0-9819-00aa0040529b"))
for identity in (r"NT AUTHORITY\SELF", "EVERYONE"):
    identity = System.Security.Principal.NTAccount(identity)
    access_rule = System.DirectoryServices.ActiveDirectoryAccessRule(
            identity,
            System.DirectoryServices.ActiveDirectoryRights.ExtendedRight,
            System.Security.AccessControl.AccessControlType.Deny,
            guid
            )
    obj_sec.AddAccessRule(access_rule)
dir_entry.ObjectSecurity = obj_sec
dir_entry.CommitChanges()

非常感谢任何帮助:)

【问题讨论】:

    标签: .net python active-directory


    【解决方案1】:

    如果您可以使用 .NET 3.5,则其中有一个名为 System.DirectoryServices.AccountManagment 的新命名空间。该命名空间中的 UserPrincipal 类将允许您通过将布尔值 UserCannotChangePassword 属性设置为 false 来设置“无法更改密码”。

    【讨论】:

    • 谢谢,看起来很有趣。我必须看看我是否可以通过 Python for .NET 桥使用那个 .NET 版本。
    猜你喜欢
    • 2012-06-26
    • 1970-01-01
    • 2013-02-26
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 2011-12-02
    • 1970-01-01
    • 2017-01-22
    相关资源
    最近更新 更多