Link to home
Start Free TrialLog in
Avatar of Tom Powers
Tom Powers

asked on

Active directory Ou with computer names in a treeview in vb.net

I am trying to create a program that  loads computernames in the treeview control limited to one OU IN vb.net
I can load a combobox like this
 Public Sub ADComputers()
        Dim dirEntry As DirectoryEntry = New DirectoryEntry()
        ' NOTE: This path should be comma delimited, not semi-colon delimited
        ' Each label in the domain name should be a separate Domain Component (DC)
        dirEntry.Path = "LDAP://OU=XXX,OU=Computer Accounts,DC=XXX,DC=XXX,DC=XXX,DC=org"


        Dim mySearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
        ' This value can be passed in the constructor if preferred.
        mySearcher.Filter = "(objectClass=Computer)"
        mySearcher.PageSize = 1001

        For Each resEnt As SearchResult In mySearcher.FindAll()
            TSCmbADC.Items.Add(resEnt.Properties("name")(0).ToString())
            ' List box is a bit simple for these unless I missed something
            ' lbADUsers.Items.Add(resEnt.Properties("sAMAccountName")(0).ToString())
            ' lbADUsers.Items.Add(resEnt.Properties("aDSPath")(0).ToString())
            ' And this one needs some work unless you're attaching to every object within the directory.
            ' lbADUsers.Items.Add(resEnt.Properties("objectGUID")(0).ToString())
        Next
        txtComputerCount.Text = TSCmbADC.Items.Count
    End Sub

Open in new window

i JUST DON'T UNDERSTAND THE TREEVIEW. Thnaks Guys
Avatar of Klavs R
Klavs R

First, add a TreeView control to the form.
To add items use this code:
Dim ouNode As New TreeNode("Your OU")
ouNode.Nodes.Add(New TreeNode("Computer 1"))
ouNode.Nodes.Add(New TreeNode("Computer 2"))
ouNode.Nodes.Add(New TreeNode("Computer 3"))
yourTreeViewControl.Nodes.Add(ouNode)

Open in new window

Hope this helps you.
Avatar of Tom Powers

ASKER

KLAVS thanks I know the amount of computers in My Ou for my Hospital is 1430 and grows every week or Month.
So how would I use just ouNode.Nodes.Add(New TreeNode("name")) in one line to loop until it is complete. then use
your statement 5:yourTreeViewControl.Nodes.Add(ouNode) line ? I appreciate your help bigtime. Thanks
ASKER CERTIFIED SOLUTION
Avatar of Klavs R
Klavs R

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Klavs R you nailed it down perfectly Thank You