Process Id for Service

  • Thread starter Thread starter Tom C
  • Start date Start date
T

Tom C

I have spent hours looking for this and just can't find how to to get
the process id of a service running on a given machine. I have a
service As System.ServiceProcess.ServiceController in hand but I can't
seem to connect the dots to get the correct Process Id. We have
multple instances of the same app running for different customers and
I need to know at a glance which instance is connected to what Process
Id. Anyone know how to do this?
 
Tom said:
We have multple instances of the same app running for different
customers and I need to know at a glance which instance is connected
to what Process Id.

Can interrogate each "instance"?

If so, you could ask /it/ to find out its own Process Id, using

System.Diagnostics.Process.GetCurrentProcess().Id


Failing that, how does each customer access their own "instance"?
Presumably there must be something that directs Customer A to one
instance and B to another.

HTH,
Phill W.
 
Can interrogate each "instance"?

If so, you could ask /it/ to find out its own Process Id, using

    System.Diagnostics.Process.GetCurrentProcess().Id

Failing that, how does each customer access their own "instance"?
Presumably there must be something that directs Customer A to one
instance and B to another.

HTH,
    Phill  W.

We know what they are in our management console by the port that they
are using and a friendly name but this information is not available to
me when trying to attach to a service with visual studio or when
looking at task manager; the port is not available; only the process
name and pid. So I have the port and friendly name in my management
console and I want to also display the pid then I can cross reference
it there and know which of the n instance to attach my debugger to.
Now if I knew how to query the instance, I would have this data right?
That is the question. All that I have in hand is a dim service As
System.ServiceProcess.ServiceController. What I need is the code to
get to the running process pid from there.
 
Tom C said:
I have spent hours looking for this and just can't find how to to get
the process id of a service running on a given machine. I have a
service As System.ServiceProcess.ServiceController in hand but I can't
seem to connect the dots to get the correct Process Id. We have
multple instances of the same app running for different customers and
I need to know at a glance which instance is connected to what Process
Id. Anyone know how to do this?

See QueryServiceStatusEx() or EnumServicesStatusEx() API functions. One of
the things they return is dwProcessId. I am not sure if there is an
equivalent library function for this. A quick search shows nothing.
 
See QueryServiceStatusEx() or EnumServicesStatusEx() API functions. One of
the things they return is dwProcessId. I am not sure if there is an
equivalent library function for this. A quick search shows nothing.

That was the missing piece. thanks so much.
 
Back
Top