title: Retrieve user information and check if member of a group in active directory using VB.NET
body: <p>I'm using the following code, which works, to login a user to an application built in VB.NET against active directory.</p>
  
  <p>This code works great but I need to retreive the user's first name, last name, display name and also check if the user is part of a group.</p>
  
  <p>I've tried many forms of adResults.Property("displayname").ToString() and the like but just can't get it to work right.</p>
  
  <p>Anyone have any ideas how to do what I'm looking to do?</p>
  
  <p>Here's the code I'm using now and thanks in advance.</p>
  
  <pre><code>Public Function ValidateActiveDirectoryLogin(ByVal sDomain As String, ByVal sUserName As String, ByVal sPassword As String) As Boolean
  
      Dim bSuccess As Boolean = False
      Dim adEntry As New System.DirectoryServices.DirectoryEntry("LDAP://" &amp; sDomain, sUserName, sPassword)
      Dim adSearcher As New System.DirectoryServices.DirectorySearcher(adEntry)
      adSearcher.SearchScope = DirectoryServices.SearchScope.OneLevel
      Try
          Dim adResults As System.DirectoryServices.SearchResult = adSearcher.FindOne
          bSuccess = Not (adResults Is Nothing)
      Catch ex As Exception
          bSuccess = False
          MsgBox("Error")
      End Try
  
      Return bSuccess
  
  End Function 
  </code></pre>