Cut*_*ert 4 .net windows winforms
有没有办法使用System.DirectoryServices.AccountManagement
命名空间获取当前登录的用户?我一直在使用以下内容:
Dim wi As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
Dim fullName As String = wi.Name.ToString
Dim loggedOnUser = fullName.Substring(fullName.IndexOf("\") + 1)
Console.WriteLine("The currently logged on user is {0}", loggedOnUser)
Run Code Online (Sandbox Code Playgroud)
但我想了解有关当前用户的更多信息,例如它们所属的组名称,并且想知道AccountManagement
命名空间是否提供了此信息.
使用它只返回我无法理解的数字字符串:
For Each item As IdentityReference In wi.Groups
Console.WriteLine(item.ToString())
Next
Run Code Online (Sandbox Code Playgroud)
你在寻找类似的东西吗?
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "login");
foreach (var group in user.GetGroups())
{
Console.WriteLine(group.Name);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:在stackoverflow的帮助下找到谷歌的帮助;-) 活动目录:获取用户所在的组
归档时间: |
|
查看次数: |
490 次 |
最近记录: |