添加引用 System.DirectoryServices
导入命名空间 using System.DirectoryServices;

c#活动目录操作srvip = "192.168.1.1";
   dn 
= "DC=l,DC=com";
c#活动目录操作user 
= @"administrator";
c#活动目录操作 pwd 
= "123";
c#活动目录操作 DirectoryEntry de;
c#活动目录操作de
= new DirectoryEntry("LDAP://" + srvip + "/" + dn, user, pwd);
c#活动目录操作DirectorySearcher sr 
= new DirectorySearcher(de, "(userPrincipalName=" + logname+")"); //要括起来

c#活动目录操作
string path = sr.FindOne().Properties["distinguishedName"][0].ToString();

CN 用户名
OU 组织
DC 域控制器 

userPrincipalName 登录名

 

 

            DirectoryEntry de;
            de = new DirectoryEntry("LDAP://" + srvip + "/" + dn, user, pwd);
            DirectorySearcher sr 
= new DirectorySearcher(de, "(CN="+textBox1.Text+")"); //要括起来
            ResultPropertyCollection pp=sr.FindOne().Properties;

            
foreach (string ppp in pp.PropertyNames)  
            {
                listBox1.Items.Add(ppp);
                
for (int i = 0; i < pp[ppp].Count; i++)
                {
                    listBox1.Items.Add(
"---------------->" + pp[ppp][i].ToString());
                }
            }

        }

相关文章:

  • 2021-12-09
  • 2022-12-23
  • 2021-12-23
  • 2021-09-10
  • 2022-12-23
  • 2021-08-24
  • 2021-11-23
  • 2021-12-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-12-14
  • 2021-12-06
  • 2022-01-25
相关资源
相似解决方案