开发者

How to know which user account runs a specific windows service?

开发者 https://www.devze.com 2023-01-12 09:33 出处:网络
How can I 开发者_开发百科know, by using C++ code, which user runs a specific service? The program I need to write might run under a local administrator account, so I guess there won\'t be permissions

How can I 开发者_开发百科know, by using C++ code, which user runs a specific service? The program I need to write might run under a local administrator account, so I guess there won't be permissions problems.

Is it possible?

TIA.


Depending on whether you need the user of the currently running service or the user specified in startup parameters of the service, see QueryServiceObjectSecurity and QueryServiceConfig functions in Windows API respectively.


Following are my suggestions but I have not tried any of them. You may use QueryServiceConfig2 API with service configuration level set to SERVICE_CONFIG_SERVICE_SID_INFO and then use the LookupAccountSid API to find the account name associated with the service. (or) You may use the ToolHelp APIs to enumerate all the processes and figure out the user account associated with the process.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号