【发布时间】: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