How do I retrieve the username that a Windows service is running under?

后端 未结 6 1083
無奈伤痛
無奈伤痛 2020-12-09 09:44

Given a service name, I would like to retrieve the username that it runs under (i.e. the username shown in the \'Log On\' tab of a service\'s properties window). There doesn

6条回答
  •  遥遥无期
    2020-12-09 10:27

    Try this:

    System.Security.Principal.WindowsIdentity.GetCurrent();
    

    but the most obvious you will get LOCAL SYSTEM or NETWORK. The reason that you cannot show this user - that service can manage multiple users (shared by desktop, attached to current windows session, using shared resource ...) System starts service, but any user can use it.

提交回复
热议问题