?
Solved

VB.NET WinForm Fill List View with AD Users

Posted on 2010-01-12
4
Medium Priority
?
873 Views
Last Modified: 2012-06-27
I have already got my List View to populate with users from AD, the problem is that I am trying to limit what shows in that list view.  
Example:  A person choosed A-F and then clicks show and it shows all users with a username that starts with A-F.
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click

        Dim dirEntry As DirectoryEntry = New DirectoryEntry("LDAP://10.10.10.235/CN=Users,DC=domain,DC=com")
        dirEntry.Username = "domain\administrator"
        dirEntry.Password = "password"
        If lbxSelectUser.Items.Count > 1 Then
            MsgBox("Patience Is Not 1 of your virtues")
        Else
            Dim mySearcher As New DirectorySearcher(dirEntry)
            mySearcher.Filter = "(&(objectClass=User)(objectCategory=person))"
            For Each resEnt As SearchResult In mySearcher.FindAll()
                lbxSelectUser.Items.Add(resEnt.Properties("sAMAccountName")(0).ToString())
            Next
            lbxSelectUser.Sorted = True
        End If
    End Sub

Open in new window

0
Comment
Question by:james_martin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Thunder724
ID: 26296995
James, in this situation what I would think of doing is placing all the AD info into a DATASET first; and use DATAVIEWS to populate your ListView. That way you can use simple SQL like syntac for the DATAVIEW FILTER.
0
 

Author Comment

by:james_martin
ID: 26297037
The problem with this is that it will take a lot of time to list this out, over 10,000 users.  The purpose of breaking it out is to cut down on time to pull information.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 26302709
You can make up the SearchFilter string like below

sn=a* (all names starting with a)
(sn=a*)(sn=b*) (all names starting with a or b)

Check here
http://msdn.microsoft.com/en-us/library/aa746475%28VS.85%29.aspx
0
 
LVL 4

Expert Comment

by:Thunder724
ID: 26302779
   
CodeCruiser's suggestion sounds like a good idea if you are only going to query a small subset once or twice at a time.  If you are going to do multiple searches then the initial time to build the dataset is, in my opinion, more economical.  
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question