Read AD security groups for the logged on user.

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.
 
N

Newbie Coder

VB4Me,

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top