简体   繁体   中英

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

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.

根据您是需要当前运行的服务的用户,还是需要该服务的启动参数中指定的用户,请分别参阅Windows API中的QueryServiceObjectSecurityQueryServiceConfig函数。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM