Solved

DirectorySearcher and Active Directory

Posted on 2004-10-28
219 Views
Last Modified: 2010-04-24
Using DirectorySearcher for VB.NET and Active Directory how do I search subdirectories for a single users account?

Dim adEntry As New DirectoryEntry("LDAP://domain/OU=X,DC=X,DC=X", user, pass)
Dim adSearch As New DirectorySearcher(adEntry)
adSearch.Filter = "(SAMAccountName=" + user + ")"
...
Dim adResult As SearchResult = adSearch.FindOne()
...

When I try the above it doesn't return anything because OU has like 20 subdirectories with users in each. But if I specify "LDAP://domain/OU=Y,OU=X,DC=X,DC=X" it now will only search OU=Y and not all subfolders of OU=X...

A complete example would be appreciated.
0
Question by:sman003
    3 Comments
     
    LVL 18

    Accepted Solution

    by:
    0
     

    Author Comment

    by:sman003
    yep actually did, though is the filter "(anr="+ username +")" the correct filter for searching by windows login name?
    0
     
    LVL 18

    Expert Comment

    by:armoghan
    I think this is the way for getting things under windows login name
    see other discussions from google
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…
    Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    913 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now