R
Rob Oldfield
Does anyone have some code that will allow me to tell if the current user of
a windows forms app is in a particular AD group?
I've looked at the IsInRole way of doing it, using something like this....
Private Function InGroup(ByVal grp As String) As Boolean
Dim id As WindowsIdentity
id = WindowsIdentity.GetCurrent()
Dim p As New WindowsPrincipal(id)
InGroup = p.IsInRole("DomainName\" + grp)
End Function
....but that only works for built-in groups like Domain Users and Domain
Admins (do I have that correct?) so is of no use to me. The groups I want
to check are custom made new ones.
I've also looked at something like this...
Dim entry As New DirectoryServices.DirectoryEntry(LDAP://Domain_Name)
Dim mySearcher As New System.DirectoryServices.DirectorySearcher(entry)
Dim result As System.DirectoryServices.SearchResult
mySearcher.Filter = ("(anr= MyGroupName)")
....which gets me the correct security group, but I'm then stuck on how I can
get at its members.
Any ideas would be most appreciated.
a windows forms app is in a particular AD group?
I've looked at the IsInRole way of doing it, using something like this....
Private Function InGroup(ByVal grp As String) As Boolean
Dim id As WindowsIdentity
id = WindowsIdentity.GetCurrent()
Dim p As New WindowsPrincipal(id)
InGroup = p.IsInRole("DomainName\" + grp)
End Function
....but that only works for built-in groups like Domain Users and Domain
Admins (do I have that correct?) so is of no use to me. The groups I want
to check are custom made new ones.
I've also looked at something like this...
Dim entry As New DirectoryServices.DirectoryEntry(LDAP://Domain_Name)
Dim mySearcher As New System.DirectoryServices.DirectorySearcher(entry)
Dim result As System.DirectoryServices.SearchResult
mySearcher.Filter = ("(anr= MyGroupName)")
....which gets me the correct security group, but I'm then stuck on how I can
get at its members.
Any ideas would be most appreciated.