Gobble45 0 Newbie Poster

Hello Daniweb.

Im currently working on a solution that involves querying a specific user (either by getting the user to 'login' or by detecting who the user is that is logged in to the machine) against the domains active directory structure to determine if they are a member of 1 of 5 groups.

If the user is a part of one of the groups, then a predefined function will execute based on which group they are in.

So far ive looked at:

  • LDAP Query
  • Windows Principal/Identity

after looking at these for a few hours, ive generally confused myself.

this is one of many things i have tried:

Public Function GetUserDetails()
        Dim MyIdentity As WindowsIdentity = WindowsIdentity.GetCurrent()
        Dim MyPrincipal As New WindowsPrincipal(MyIdentity)
        Return MyPrincipal.IsInRole("DOMAINNAME\GROUPNAME")
End Function


Private Sub frmMainMenu_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim usertype As boolean = GetUserDetails()
    If usertype = "True" Then
    Elseif usertype = "False" then
    End if

This always returns false, and i have checked the spelling atleast 10 times.

I found and manipulated the code here: http://stackoverflow.com/questions/3026909/determine-if-a-user-belongs-to-a-particular-ad-group-using-net to produce what i have written above.

I guess the "finding if user in group" part is one thing, but i need to query against 5 groups of different names and execute different functions based on the group the user is in. (BTW The user will be in only 1 of the 5 groups.)

Could someone enlighten me with way of doing this, and maybe an example.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.