Hi,
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.
Hi,
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.