1 Previous Next 

List Computers in Active Directory Network


You can use the directory searcher to list all the computers in your active directory network. Yo need to add a reference to system.directoryservices and an import to the same for this example. To use this sample, drag a combobox on a form and change "YourNetWorkName" in the right one. In the current version is thows the users. Private Sub Form1_Load(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles MyBase.Load
   Dim DirEntry As New DirectoryEntry("LDAP://YourNetWorkName")
   Dim DirSearch As New DirectorySearcher(DirEntry)
   'DirSearch.Filter = "(objectClass=*)"
   'The above is the default
   'DirSearch.Filter = "(objectClass=computer)"
    DirSearch.Filter = "(objectClass=user)"
   'DirSearch.Filter = "(objectClass=FirstName)"
   'DirSearch.Filter = "(objectClass=LastName)"
    For Each sr As SearchResult In DirSearch.FindAll
        Try
          ComboBox1.Items.Add(sr.GetDirectoryEntry.Name.ToString.Substring(3))
          Catch
            'a very dirty way to skip GetDerectoryEntrys with no Name
        End Try
    Next
    ComboBox1.SelectedIndex = 0
End Sub



1 Previous Next