Read AD security groups for the logged on user.

  • Thread starter Thread starter vb4me
  • Start date Start date
V

vb4me

Does anyone have any working example code to read the AD security
groups a particular user might belong to?
Preferably using the user returned from the following snippet, and not
a 'username' 'password' type of call.

Here's the snippet to return current logged-on user

Dim myDomain As AppDomain = System.Threading.Thread.GetDomain()
myDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal)
Dim myPrincipal As System.Security.Principal.WindowsPrincipal
= CType(System.Threading.Thread.CurrentPrincipal,
System.Security.Principal.WindowsPrincipal)
MsgBox(myPrincipal.Identity.Name.ToString())

from here I can easily find the LOCAL groups that a user belongs to
with some code like in the following snippet:
Dim wbirFields As Array =
[Enum].GetValues(GetType(System.Security.Principal.WindowsBuiltInRole))
Dim roleName As Object
For Each roleName In wbirFields
Try
If myPrincipal.IsInRole(CType(roleName,
System.Security.Principal.WindowsBuiltInRole)) Then
MsgBox(roleName.ToString)
End If
End Try
Next roleName

But, what I really need is to get the AD groups that this user might
belong to (without respecifying un/pw)

The big picture here that I'm trying to accomplish is to display
different forms/controls for users assigned to different AD groups.
Ex: if the user running the program is assigned to the SalesOrderAdmin
group then enable the order deletion screen, if they are assigned to
the SalesOrderEntry group they wouldn't be able to access those
functions. If they are part of the SalesOrderExpidite group only allow
reading, etc

Suggestions?

Thanks in advance.
 
VB4Me,

Search for ADSI examples. There are some on Code Project & Planet Source Code
 
Back
Top