在使用 C#的.NET中如何获取当前用户名?

11 浏览
0 Comments

在使用 C#的.NET中如何获取当前用户名?

如何在使用C#的.NET中获取当前用户名?

admin 更改状态以发布 2023年5月22日
0
0 Comments

如果您处于用户网络中,则用户名将不同:

Environment.UserName
- Will Display format : 'Username'

而不是

System.Security.Principal.WindowsIdentity.GetCurrent().Name
- Will Display format : 'NetworkName\Username'

请选择您想要的格式。

0
0 Comments
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

(这是一个HTML标签,含义为加粗显示123)

0