Reading a list of users from XP

S

sam smith

I am using VS 2005 (VB.NET) and I would like to get a list of all users who
have accounts on the server. How can I do this and populate a listbox with
the information?

Thanks in advance
 
T

The Grim Reaper

I have done this, at work, using fairly simple code. It works on Server
2003 and XP.
Unfortunately, the source code is at work and I can't remember how I did
it!!
However, I do remember that it used an Active Directory type function - even
though we don't use AD at all at work.

If no-one's replied in the next 24 hours, I'll give you my code!!
__________________________
The Reaper
 
B

BK

This is crude, but it should get you started. This code will give you
all the users in AD:

Console.WriteLine("** Listing Start")

Dim oDirectoryEntry As DirectoryServices.DirectoryEntry = New
DirectoryEntry("LDAP://SomeDomainHere")
Dim oDirectorySearcher As DirectorySearcher = New
DirectorySearcher(oDirectoryEntry)

oDirectorySearcher.Filter = ("(ObjectClass=User)")
Dim oResult As SearchResult = oDirectorySearcher.FindOne
For Each oResult In oDirectorySearcher.FindAll
Console.WriteLine(oResult.GetDirectoryEntry().Name)
Next

Console.WriteLine("Listing End **")
 
S

Sam Smith

I copied the code into my project but my DirectoryServices are not defined.
How can I do that? Do I need to import a namespace? If so, which one? I
ran through Imports system. and couldn't find DirectoryServices.

Any help would be appreciated.
 
B

BK

I copied the code into my project but my DirectoryServices are not defined.
How can I do that? Do I need to import a namespace? If so, which one? I
ran through Imports system. and couldn't find DirectoryServices.

Yep...

Imports System.DirectoryServices
 
S

Sam Smith

There is no System.DirectoryServices when I look at intellisense. Is there
something else to import first?

VS 2005 VB.NET
 
T

The Grim Reaper

Add a reference to System.DirectoryServices in the My Project thingammybob.
It's not referenced by default.
__________________________
The Reaper
 
S

Sam Smith

I added the reference to DirectoryServices into my project and it now works.
Thanks for the tip.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top