Link to home
Start Free TrialLog in
Avatar of Ryan Smith
Ryan SmithFlag for United States of America

asked on

VB.Net listbox only getting 1000 systems

I'm writing code to get computers from AD. The problem I'm having is that its not getting all the computers from the directory. It seems like the ListBox only gets 1000 systems. Is there anyway to increase this?
Avatar of it_saige
it_saige
Flag of United States of America image

What is the code you use to get the computers from AD?

-saige-
are you using a IN clause in the query to retrieve the data? (not sure with MSSQLSever? but Oracle has a limit of 1000 items on the IN clause)
May just be a coincidence but without any of your code examples or more explanation its a good shot in the dark ;)
Avatar of Ryan Smith

ASKER

Sorry.. i forgot to add the code..


       'Clears listbox
        results.Items.Clear()

        'Connect to AD Database
        Dim rootEntry As New DirectoryEntry("GC://DC=Domain,DC=org", Domain.Text + userID.Text, password.Text)

        'Set What you want to search for
        Dim searcher As New DirectorySearcher(rootEntry)
        searcher.PropertiesToLoad.Add("cn")
        searcher.PropertiesToLoad.Add("mail")

        'Set Your Search Filter
        searcher.Filter = "(objectCategory=Computer)"

        'Finds all
        Dim queryResults As SearchResultCollection
        queryResults = searcher.FindAll()

        'Puts the results into a list Box
        Dim result As SearchResult
        For Each result In queryResults
            results.Items.Add(result.Properties("cn")(0))
        Next

Open in new window

you have confirmed that the record set (queryResults) is returing with more than a 1000 items?
Not sure.... This is the code below it.. What it does is exports the code out to a text file. The text file itself only has 1000 items.. Maybe its the code and not the list box?

        If (Not System.IO.Directory.Exists("c:\CCPRemote")) Then
            System.IO.Directory.CreateDirectory("c:\CCPRemote")
        End If



        Dim W As IO.StreamWriter
        Dim i As Integer
        W = New IO.StreamWriter("c:\CCPRemote\computers.txt")

        For i = 0 To results.Items.Count - 1
            W.WriteLine(results.Items.Item(i))
        Next
        W.Close()

Open in new window

Basically it's putting the results in a text file.
I agree with Glen, first let's confirm that the record set is returning more than 1000 items.

Otherwise, I am not finding anything that would limit the amount of items that you are displaying.

-saige-
Something like:
Dim de As DirectoryEntry = New DirectoryEntry("GC://DC=Domain,DC=org", Domain.Text + userID.Text, password.Text)
Dim searcher As DirectorySearcher = New DirectorySearcher(de, "(objectCategory=Computer)")
Dim queryResults As SearchResultCollection
searcher.PropertiesToLoad.Add("cn")
searcher.PropertiesToLoad.Add("mail")
queryResults = searcher.FindAll()

If Not queryResults Is Nothing AndAlso queryResults.Count > 0 Then
	MessageBox.Show(String.Format("Directory search returned {0}", IIf(queryResults.Count = 1, String.Format("{0} record", queryResults.Count), String.Format("{0} records", queryResults.Count))))
	results.Items.Clear()
	For Each result As SearchResult In queryResults
		results.Items.Add(result.Properties("cn")(0))
	Next
Else
	results.Items.Add("No search results found")
End If

Open in new window


-saige-
Let me qualify my previous statement.  The listbox does have limits on what can be displayed (or the total number of items that can be added), but from the set of data you are returning I do not see anything that would challenge the limits imposed.

-saige-
Here's what it said.. 1000 records see screenshot

User generated image
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

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
Wow.. I'd never would have thought of that. Thank you.. It's now returning all my results :)