0
从脚本创建Active Directory用户时,我还需要设置它们不能更改其密码的选项。通过管理GUI,可以轻松完成,方法是选中“用户无法更改密码”。然而,以编程方式,这是另一回事。我发现recipe涉及与ADSI COM API交互,但出于技术原因,我希望通过.NET API完成相同操作(简短版本:我无法通过脚本访问ADSI COM API) 。防止Active Directory用户使用DirectoryServices更改他/她的密码
我曾尝试翻译上述配方纯.NET,因为在这条巨蟒片段中可以看出,但不幸没有影响:
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()
将不胜感激任何帮助:)
谢谢,看起来很有趣。我将不得不查看是否可以通过Python for .NET桥接来使用该.NET版本。 – aknuds1 2010-02-03 15:14:49
非常感谢,这个解决方案非常完美! – aknuds1 2010-02-03 19:57:18