المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Active Directory... C#... How do I get the users windows login? Help please. [modified]



C# Programming
07-11-2009, 02:11 AM
Ok now I got the User Names now I am needing help on learning how to filter the list so that I get all persons and not the junk loging such as DHCP Administrator, DNSUpdateProxy groups, etc...
I only want persons...


public void ShowDomainUsers()
{
string filter = "";
//DirectoryEntry domain = new DirectoryEntry("LDAP://domain.com/CN=Users,DC=Domain,DC=com");
try
{
if (File.Exists(Environment.CurrentDirectory + "\\Debug.txt"))
{
MessageBox.Show("LDAP://" + cboDomains.Text + "/CN=Users,DC=" + Left(cboDomains.Text, (cboDomains.Text.IndexOf(".", 0))) + ",DC=" + Right(cboDomains.Text, (cboDomains.Text.Length - cboDomains.Text.IndexOf(".", 0) - 1)));
}
using (DirectoryEntry domain = new DirectoryEntry("LDAP://" + cboDomains.Text + "/CN=Users,DC=" + Left(cboDomains.Text, (cboDomains.Text.IndexOf(".", 0))) + ",DC=" + Right(cboDomains.Text, (cboDomains.Text.Length - cboDomains.Text.IndexOf(".", 0) - 1))))
//root and filter and propertiestoload I do not know what to put
//filter = "(objectCategory=person)(objectClass=user)";
//using (DirectorySearcher searcher = new DirectorySearcher(root,filter,propertiestoload))
//using (SearchResultCollection results = searcher.FindAll())

//sAMAccountName -- THIS IS WHAT I want to get the USER Login names

foreach (DirectoryEntry child in domain.Children)
{
//Console.WriteLine(child.Name);

//lbxDomainUsers.Items.Add(new ListViewItem(new string[] {Right(child.Name, (child.Name.Length - 3)), child.Username}));

lbxDomainUsers.Items.Add(Right(child.Name, (child.Name.Length - 3)) + " | " + child.Properties["sAMAccountName"].Value);// Username);
}
}
catch
{
MessageBox.Show("We are having a problem with the active directory.");
}
}

modified on Friday, July 10, 2009 5:37 PM