Compatible Support Forums: VB.NET Return Active Directory UserNames

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

VB.NET Return Active Directory UserNames

#1 User is offline   Atreyu 

  • enthusiast
  • Group: Members
  • Posts: 297
  • Joined: 04-July 01

Posted 22 October 2003 - 05:38 AM

Using VB.NET...

I created a program that randomly generates usernames. Now I need it to search the Active Directory to ensure the username does not already exist. How would I search my Active Directory to return a matching username? Also, how would I query Active Directory to return a listing of all usernames? This was easy in VB6... but doesn't seem to be as straight-forward now.

Thanks in advance.
0

#2 User is offline   sapiens74 

  • Pooh-Bah
  • Group: Members
  • Posts: 1915
  • Joined: 30-March 00

Posted 22 October 2003 - 07:04 AM

Are you using Server 2003?
0

#3 User is offline   Atreyu 

  • enthusiast
  • Group: Members
  • Posts: 297
  • Joined: 04-July 01

Posted 22 October 2003 - 09:01 PM

It shouldn't matter, but yes... it's on a couple servers (mixed with 2k).

Either way, I figured it out. I'll post the code when I get off of work.
0

#4 User is offline   sapiens74 

  • Pooh-Bah
  • Group: Members
  • Posts: 1915
  • Joined: 30-March 00

Posted 22 October 2003 - 11:25 PM

I misunderstood the questions.


I thought you were trying to query AD for specific users.


With Server 2003 you can use DSGET command


But since you are talking programming, thats not my thing :P
0

#5 User is offline   Atreyu 

  • enthusiast
  • Group: Members
  • Posts: 297
  • Joined: 04-July 01

Posted 22 October 2003 - 11:37 PM

No problem. Here's what I found to work. It returns the user's name, their path, and also their alias (or username).

Code:
        Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://mydomain")
        ''Console.Write(enTry.Username)
        Dim mySearcher As DirectorySearcher = New DirectorySearcher(enTry)
        mySearcher.Filter = "(objectClass=User)"
        Dim resEnt As SearchResult
        For Each resEnt In mySearcher.FindAll()
            Console.WriteLine(resEnt.GetDirectoryEntry().Name.ToString())
            Console.WriteLine(resEnt.GetDirectoryEntry().Properties("sAMAccountName").Value.ToString())
            Console.WriteLine(resEnt.GetDirectoryEntry().Path.ToString())
            Console.WriteLine(resEnt.GetDirectoryEntry().NativeGuid.ToString())
            Console.WriteLine("===========================================")
        Next

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users