我使用以下代码使用VB.Net 1.1从AD获取名字,姓氏,电子邮件和部门
int bind_lo(int port) {
int rv;
const char iface[] = "lo";
struct sockaddr_in addr;
rv = socket(AF_INET, SOCK_STREAM, 0);
if (rv < 0) return -1;
bzero((char *) &addr, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
addr.sin_port = htons(port);
if (bind(rv, (struct sockaddr *) &addr, sizeof(addr)) < 0)
return -2;
if (setsockopt(rv, SOL_SOCKET, SO_BINDTODEVICE, iface, strlen(iface) + 1) < 0) {
return -3;
}
return rv;
}
但我无法获得这些属性。在
Dim str As String = String.Format(“{0}”,Onn)
只有15个属性,并且没有名字,姓氏,电子邮件和部门。我做错了什么?
答案 0 :(得分:0)
你的代码虽然过时,看起来很好看。如果您坚持继续使用您的代码,我稍后会看一下。
与此同时,此代码应符合您的具体情况:
Dim user As DirectoryEntry = New DirectoryEntry("UserDN")
Dim src As DirectorySearcher = New DirectorySearcher(user, "(&(objectClass=user)(objectCategory=Person))")
src.PropertiesToLoad.Add("sn")
src.PropertiesToLoad.Add("givenName")
src.PropertiesToLoad.Add("mail")
src.PropertiesToLoad.Add("department")
Dim res As SearchResult = src.FindOne
Console.WriteLine(res.Properties("sn")(0))
Console.WriteLine(res.Properties("givenName")(0))
Console.WriteLine(res.Properties("mail")(0))
Console.WriteLine(res.Properties("department")(0))
Console.ReadLine()