Read AD security groups for the logged on user.



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()
Dim myPrincipal As System.Security.Principal.WindowsPrincipal
= CType(System.Threading.Thread.CurrentPrincipal,

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 =
Dim roleName As Object
For Each roleName In wbirFields
If myPrincipal.IsInRole(CType(roleName,
System.Security.Principal.WindowsBuiltInRole)) Then
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


Thanks in advance.

Newbie Coder


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