C# 获取当前用户的名称(不是用户名)

C# 获取当前用户的名称(不是用户名),c#,winforms,C#,Winforms,我读过一些关于获取当前用户名称的帖子,这些帖子使用以下方法之一: Environment.UserName; System.Security.Principal.WindowsIdentity.GetCurrent().Name 这将获取当前登录用户的用户名,但我想知道的是如何获取登录用户的名称? (因此,不是登录名,而是锁定计算机时保存和显示的名称) 这个代码对我有用 using System.DirectoryServices.AccountManagement; UserPrincip

我读过一些关于获取当前用户名称的帖子,这些帖子使用以下方法之一:

Environment.UserName;
System.Security.Principal.WindowsIdentity.GetCurrent().Name
这将获取当前登录用户的用户名,但我想知道的是如何获取登录用户的名称? (因此,不是登录名,而是锁定计算机时保存和显示的名称)

这个代码对我有用

using System.DirectoryServices.AccountManagement;

UserPrincipal userPrincipal = UserPrincipal.Current;
String name = userPrincipal.DisplayName;