VB.NET Return Active Directory UserNames

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 ...




Topic Options
#132355 - 10/22/03 05:38 AM VB.NET Return Active Directory UserNames
Atreyu Offline
enthusiast

Registered: 07/04/01
Posts: 297
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.

Top
Advertisement
#132359 - 10/22/03 07:04 AM Re: VB.NET Return Active Directory UserNames
sapiens74 Offline
Pooh-Bah

Registered: 03/30/00
Posts: 1915
Are you using Server 2003?

Top
#132392 - 10/22/03 09:01 PM Re: VB.NET Return Active Directory UserNames
Atreyu Offline
enthusiast

Registered: 07/04/01
Posts: 297
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.

Top
#132398 - 10/22/03 11:25 PM Re: VB.NET Return Active Directory UserNames
sapiens74 Offline
Pooh-Bah

Registered: 03/30/00
Posts: 1915
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

Top
#132399 - 10/22/03 11:37 PM Re: VB.NET Return Active Directory UserNames
Atreyu Offline
enthusiast

Registered: 07/04/01
Posts: 297
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

Top


Forums
Windows Support Forums
Everything New Technology
Legacy OS
Hardware
Software
Games
Networking
Customization & Tweaking
Security

Linux Support Forums
Everything Linux
Linux Hardware
Linux Software
Linux Games
Linux Networking
Linux Customization & Tweaking
Linux Security

Apple Support Forums
Everything Apple
Recent Topics
Router keeps disconnecting internet
by rfboyd
Yesterday at 04:18 PM
Program Running When Starting Computer
by cbk
12/05/09 11:05 AM
System Crashing Error 1000008e, 1000000a, 0000004e
by PapaPrem
11/30/09 06:01 PM
Starcraft Broodwar Campaign Crash Problem
by Lurker02
11/30/09 12:33 PM
How do I affect the order of ALT-Tab?
by KenJackson
11/28/09 10:10 PM
Who's Online
0 Registered (), 178 Guests and 37 Spiders online.
Key: Admin, Global Mod, Mod
Forum Stats
91268 Members
24 Forums
58365 Topics
188861 Posts

Max Online: 1079 @ 03/12/08 01:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22