search in AD

  • Thread starter Thread starter Guest
  • Start date Start date
¤ How Can I do for search a computer in my Active Directory with vb .net?

You can use the System.DirectoryServices namespace:

Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDN As String = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDN)
Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)

ADSearch.Filter = ("(&(objectClass=computer)(name=computername))")
ADSearch.SearchScope = SearchScope.Subtree

Dim ComputerFound As SearchResult = ADSearch.FindOne()

If Not IsNothing(ComputerFound) Then
MsgBox("Computer was found!")
Else
MsgBox("Computer was not found.")
End If


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top