繁体   English   中英

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

[英]Getting the name of the current user (not the username)

我已经阅读了一些有关获取当前用户名称的帖子,这些帖子使用以下两种方法之一:

Environment.UserName;
System.Security.Principal.WindowsIdentity.GetCurrent().Name

这将获取当前已登录用户的用户名,但是我想知道如何获取已登录用户的名称? (因此不是登录名,而是锁定计算机时也会保存并显示的名称)

using System.DirectoryServices.AccountManagement;

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

该代码对我有用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM