我使用以下代码登录用户名。
private string GetLoggedInUser()
{
string userName = "";
if (System.Security.Principal.WindowsIdentity.GetCurrent() != null)
{
userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
}
return userName;
}
只是不明白为什么它没有提供登录的用户名,而是以这种格式NT AUTHORITY\SYSTEM
返回数据,但我想得到用户名。
我尝试将我的服务作为Local Service and local system account
运行,但在每种情况下,我都会收到此字符串NT AUTHORITY\SYSTEM
,而不是登录用户名。
所以请指导我在代码中更改什么。感谢