Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello every body

i have implemented a c# windows application.

for that application i want to provide login from windows user credentails.

now the issue is i need to get the users list from windows pc through code.

how to get users list eaither user created in winnt folder (under local users and groups) or user created in active directory domain.


i have an idea for get users list from winnt folder
that is

C#
DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName);
// DirectoryEntry admGroup = localMachine.Children.Find("Guests", "group");
// DirectoryEntry admGroup = localMachine.Children.Find("administrators", "group");
DirectoryEntry admGroup = localMachine.Children.Find("users", "group");
//DirectoryEntry admGroup = localMachine.Children.Find("TestUser1", "group");
object members = admGroup.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members)
{
    DirectoryEntry member = new DirectoryEntry(groupMember);
    listBox1.Items.Add(member.Name);
}

But now i want to list out users, if he is exist in active directory or winnt folder

any body give me code for this to cross verify users from both throug c# code

[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]
Posted
Updated 9-Dec-11 21:11pm
v2

1 solution

This should help: http://www.freevbcode.com/ShowCode.asp?ID=7892[^] - it's in VB, but the mechanics of the process are the same in C# so it';s a simple conversion.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900