从脚本创建活动目录用户时,我还需要设置他们不能更改密码的选项。通过管理GUI,通过检查“用户不能更改密码”,这很容易实现。然而,从程序上讲,这是另一回事。我发现了一个recipe,它涉及到与adsicomapi的交互,但是出于技术原因,我希望通过.netapi来实现同样的功能(短版本:我无法从脚本访问adsicomapi)。在
我曾尝试将上述配方转换为pure.NET,正如在这个Python片段中可以看到的,但不幸的是,它没有任何效果:
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()
非常感谢您的帮助:)
如果您可以使用.NET3.5,则会有一个新的名称空间
System.DirectoryServices.AccountManagment
。该命名空间中的UserPrincipal
类允许您通过将booleanUserCannotChangePassword属性设置为false来设置“cannotchangepassword”。在相关问题 更多 >
编程相关推荐