Checking User Group in Active Directory using VB.net

Hi

i am new to .net and active directory.

i need to validate user in Active directory.

my input data is Domain name , Username and groupName and i won't pass password


private function chechkUser(ByVal domain As String, ByVal username As String, ByVal GroupName As String) As Boolean

if username is found in active directory

chechkUser = true
else
chechkUser = false

end function

how to resolve this
can any send VB.net code for this requirement
thanx in advance

-naren




Answer this question

Checking User Group in Active Directory using VB.net

  • Naolin

    Pretty easy in VS2005

    If My.User.IsInRole("Group Name") Then
    Return True
    Else
    Return False
    End If

    VS2003 takes a little more work. Post again if you need an example for the older version.



  • Kamii47

    this following statement works for me..

    i dont know whether it is correct approach

    This statement validates my domain,group and user

    If System.Environment.UserDomainName = "DomainName" And My.User.IsInRole("GroupName") Then

    MsgBox("True")

    Else

    MsgBox("false")

    End If



  • jchau

    Hi thanks a lot for your reply.....it works for group

    but i need validate along with Domain and user name as well

    eg..

    if Domain="mydomain" and groupname= "mygroupname" and username="myuser" then

    return true

    else

    return false

    end if

    how to do that VS2005

    Thanks in advance



  • datahook

    thanks.

    i need to check only for the current logged on user



  • Cam Evenson

    Sorry, didn't read you close enough... That's getting pretty complex and I think you'll need to use LDAP queries to get your answer.

    You can add a reference to System.DirectoryServices to get some objects that facilitate Active Directory lookups.

    Keep in mind that a lot of this will depend on the security level of the user running the application... Cross domain lookups will need to be configured and allowed in AD as well.



  • Kripz

    Hi ,

    is this correct

    If System.Environment.UserDomainName = "DomainName" And My.User.IsInRole("GroupName") Then

    MsgBox("True")

    Else

    MsgBox("false")

    End If



  • RPagels

    Yeah, that works for the current user. I just noticed that your desired function contains the user and domain as parameters so I wasn't sure if you wanted to check for users or domains other than the current.

    If all you need to check are the current logged on user in their current domain then you've got your answer! If you want to check any user in any domain that you've got permission to query than you'll need to use LDAP.

    Good Luck



  • Checking User Group in Active Directory using VB.net