Process Id for Service

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?
 
P

Phill W.

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.
 
T

Tom C

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.
 
N

Nobody

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.
 
T

Tom C

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top