如何从Windows服务c#登录用户名

时间:2015-04-21 14:03:32

标签: c# windows-services

我使用以下代码登录用户名。

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,而不是登录用户名。

所以请指导我在代码中更改什么。感谢

0 个答案:

没有答案