[英]How to know if AD Group is member of other AD Group. (VB.net)
我试图在此示例中获得与IsInRole类似的结果:
Dim MyPrincipal As New System.Security.Principal.WindowsPrincipal(New System.Security.Principal.WindowsIdentity(TextBox2.Text))
If MyPrincipal.IsInRole("DOMAIN\GroupName")
Then MsgBox("User is Member of AD Group")
End If
但是我需要对组执行此操作,在这种情况下,MyPrincipal.IsInRole将不起作用(我认为这仅适用于用户帐户),并且之前从未尝试过对组进行操作,因此甚至不知道从哪里开始。 有人可以帮忙吗?
已经找到答案,如果有兴趣的话,可以使用GroupPrincipal类实现:
https://msdn.microsoft.com/zh-CN/library/bb339975(v=vs.110).aspx
例:
**
Dim ctx As New PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain, "fabrikam.com", "DC=fabrikam,DC=com", "administrator", "SecretPwd123")
Dim grp As GroupPrincipal = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "Administrators")
If grp IsNot Nothing Then
For Each p As Principal In grp.GetMembers(False)
If TypeOf p Is GroupPrincipal Then
Console.WriteLine(p.Name)
End If
Next
grp.Dispose()
End If
ctx.Dispose()
**
非常感谢保罗!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.