【发布时间】:2015-08-01 20:05:57
【问题描述】:
我正在寻找确定计算机是否是 AD 组的成员,或者甚至使用 VB.net 获取属于 AD 组成员的所有计算机。我找到了几个用于检查用户是否是组成员的示例,但没有找到用于检查计算机的示例。我希望将此功能转换为在组中搜索计算机,但没有成功。任何援助将不胜感激。提前谢谢你。
Function IsInGroup(GroupName) As Boolean
Dim MyIdentity As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
Dim MyPrincipal As System.Security.Principal.WindowsPrincipal = New System.Security.Principal.WindowsPrincipal(MyIdentity)
Return MyPrincipal.IsInRole(GroupName)
End Function
【问题讨论】:
-
我找到了这个,但我还不够好,无法将其转换为 vb.net。有人可以帮我吗?
Set objSysInfo = CreateObject("ADSystemInfo") strComputer = objSysInfo.ComputerName Set objComputer = GetObject("LDAP://" & strComputer) objmemberOf = objComputer.GetEx("memberOf") For Each objGroup in objmemberOf groupCN = Split(objGroup, ",") groupName = Mid(groupCN(0),4) Next Select Case groupName Case "TestGroup" Wscript.Echo groupName Case Else Wscript.Echo "" End Select
标签: vb.net