c#如何获取当前windows域账号
展开全部
Environment.UserName就是当前用户名
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
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的,做个任务
{
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的,做个任务
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询