c#如何获取当前windows域账号

如题所述

第1个回答  2014-01-21
Environment.UserName就是当前用户名
第2个回答  2014-01-28
private string GetCurrentFullName()
{
string DomainName = System.Environment.UserDomainName;
string AccountName = System.Environment.UserName.ToLower();
DirectoryEntry de = new DirectoryEntry("LDAP://" + DomainName);
DirectorySearcher ds = new DirectorySearcher(de);
ds.Filter = ("(objectClass=user)");

foreach (SearchResult sr in ds.FindAll())
{
string fullName = sr.GetDirectoryEntry().Name.ToString();
if (sr.GetDirectoryEntry().Properties["samaccountname"].Value.ToString().ToLower() == AccountName)
{
return fullName.Substring(3, fullName.Length-3);
}
}
return "";
}
纯COPY的,做个任务

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网