Home All Groups Group Topic Archive Search About
Author
23 Nov 2006 5:16 PM
sgr
How Can I do for search a computer in my Active Directory with vb .net?

Thanks

Author
28 Nov 2006 8:38 PM
Paul Clement
On Thu, 23 Nov 2006 09:16:01 -0800, sgr <s**@discussions.microsoft.com> wrote:

¤ 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)