我已经阅读了一些关于获取当前用户名称的帖子,这些帖子使用以下任一方法:
Environment.UserName;
System.Security.Principal.WindowsIdentity.GetCurrent().Name
这会获取当前登录用户的用户名,但我想知道的是如何获取登录用户的名称? (因此不是登录,而是在锁定计算机时也保存并显示的名称)
答案 0 :(得分:0)
using System.DirectoryServices.AccountManagement;
UserPrincipal userPrincipal = UserPrincipal.Current;
String name = userPrincipal.DisplayName;
此代码适合我