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

后端 未结 6 1093
無奈伤痛
無奈伤痛 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:34

    WMI is your friend. Look at Win32_Service, specifically the StartName property. You can access WMI from C# via the System.Management.ManagementClass.

    If you've not used WMI before, this article seems to be quite a good tutorial.

提交回复
热议问题