导入命名空间 using System.DirectoryServices;
srvip = "192.168.1.1";
dn = "DC=l,DC=com";
user = @"administrator";
pwd = "123";
DirectoryEntry de;
de= new DirectoryEntry("LDAP://" + srvip + "/" + dn, user, pwd);
DirectorySearcher sr = new DirectorySearcher(de, "(userPrincipalName=" + logname+")"); //要括起来
string path = sr.FindOne().Properties["distinguishedName"][0].ToString();
dn = "DC=l,DC=com";
user = @"administrator";
pwd = "123";
DirectoryEntry de;
de= new DirectoryEntry("LDAP://" + srvip + "/" + dn, user, pwd);
DirectorySearcher sr = new DirectorySearcher(de, "(userPrincipalName=" + logname+")"); //要括起来
string path = sr.FindOne().Properties["distinguishedName"][0].ToString();
CN 用户名
OU 组织
DC 域控制器
userPrincipalName 登录名
Code