阻止Active Directory用户使用DirectoryServices更改其密码

2024-09-26 18:05:23 发布

您现在位置:Python中文网/ 问答频道 /正文

从脚本创建活动目录用户时,我还需要设置他们不能更改密码的选项。通过管理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()

非常感谢您的帮助:)


Tags: 用户脚本obj密码accessdirsecrule

热门问题