views:

146

answers:

1

I'm looking for a good way to find the process ID of a particular Windows Service.

In particular, I need to find the pid of the default "WebClient" service that ships with Windows. It's hosted as a "local service" within a svchost.exe process. I see that when I use netstat to see what processes are using what ports it lists [WebClient] under the process name, so I'm hoping that there is some (relatively) simple mechanism to find this information.

+3  A: 

QueryServiceStatusEx returns a SERVICE_STATUS_PROCESS, which contains the process identifier for the process under which the service is running.

You can use OpenService to obtain a handle to a service from its name.

James McNellis
Thanks, worked like a charm. I think it should be OpenService rather than CreateService to obtain the handle, though.
Gerald
No problem; you're correct about `OpenService`; I've fixed that.
James McNellis