如何从活动目录中获取全名 [英] how to get complete name from active directory

查看:75
本文介绍了如何从活动目录中获取全名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

在这里,我创建了一个代码来检查当前用户是否在活动目录中退出


hi to all!

here i create a code to check that current user exit in active directory or not


string userName_AD = Environment.UserName;
            DirectoryEntry de = new DirectoryEntry("LDAP://ksjdhfiuh");
            DirectorySearcher ds = new DirectorySearcher(de);
            ds.SearchScope = SearchScope.Subtree;
            ds.Filter = "(&(objectClass=User)(sAMAccountName=" + userName_AD + "))";





现在我想获取当前用户ID的完整名称





now i want to get the complete Name of current user id

推荐答案

查看此CP文章.
方法:(几乎)通过C#将Active Directory中的所有内容 [
Check this CP article out.
Howto: (Almost) Everything In Active Directory via C#[^].

Perhaps it can help you some more help :-)


string[] properties = new string[] { "fullname" };
            string userName_AD = Environment.UserName;
            DirectoryEntry de = new DirectoryEntry("LDAP://DOMAINName");
            DirectorySearcher ds = new DirectorySearcher(de);
            ds.SearchScope = SearchScope.Subtree;
            ds.Filter = "(&(objectClass=User)(sAMAccountName=" + userName_AD + "))";
            SearchResult result = ds.FindOne();
            DirectoryEntry directoryEntry = result.GetDirectoryEntry(); 
            string displayName = directoryEntry.Properties["displayName"][0].ToString();


这篇关于如何从活动目录中获取全名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆