Check if a Windows service running

T

tshad

What would be a good way to check programmatically whether a service was
running?

We have a service that dies periodically and I need to check to see if this
service is running. I know how to check to see if the status is in stopped
or running mode. But that doesn't tell me if it is actually running.

I need to know this so that if it happens I can programmatically start the
same service on another machine.

What I would like to do is build a service that just periodically checks
(about once a minute) to see if the other service is actually running.

Thanks,

Tom
 
M

Michael Nemtsev

Hello tshad,

If you are not the author of service you definitely can't know running it
or not, because for example web-Methods Server services start really running
after 20 mins as service set "running" status.

The only way to check whether it run is to check that files/environment that
service control

t> What would be a good way to check programmatically whether a service
t> was running?
t>
t> We have a service that dies periodically and I need to check to see
t> if this service is running. I know how to check to see if the status
t> is in stopped or running mode. But that doesn't tell me if it is
t> actually running.
t>
t> I need to know this so that if it happens I can programmatically
t> start the same service on another machine.
t>
t> What I would like to do is build a service that just periodically
t> checks (about once a minute) to see if the other service is actually
t> running.
t>
t> Thanks,
t>
t> Tom
t>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
T

tshad

Michael Nemtsev said:
Hello tshad,

If you are not the author of service you definitely can't know running it
or not, because for example web-Methods Server services start really
running after 20 mins as service set "running" status.

I am the author of the service.

But I have a service that sends out emails that shows in running mode and
for some reason it dies once every 5 or 6 days and seems to be frozen (could
be in an infinite loop - but I can't find where that would happen). The
status in the services windows or when I request it from another program
shows it as running (which would make sense if it never hit the Stop code.

I need to find a good way to monitor it to tell if it has stopped or not
(until I can find the problem with the code).

BTW, when I get to this point, I can't stop the program at all. I need to
reboot the server to get it released.
The only way to check whether it run is to check that files/environment
that service control

Not sure what you mean here.

Thanks,

Tom
 
M

Michael Nemtsev

Hello tshad,

I'm not sure that such brutal way to fix you service is a good way :)

Why not to make some internal check, for example whether email was send or
not or for example each day in midnight restart service.



t> t>t> I am the author of the service.
t>
t> But I have a service that sends out emails that shows in running mode
t> and for some reason it dies once every 5 or 6 days and seems to be
t> frozen (could be in an infinite loop - but I can't find where that
t> would happen). The status in the services windows or when I request
t> it from another program shows it as running (which would make sense
t> if it never hit the Stop code.
t>
t> I need to find a good way to monitor it to tell if it has stopped or
t> not (until I can find the problem with the code).
t>
t> BTW, when I get to this point, I can't stop the program at all. I
t> need to reboot the server to get it released.
t>t> Not sure what you mean here.
t>
t> Thanks,
t>
t> Tom
t>---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
A

Andy

On way would be to have teh service right to a db table every now and
then, and have another service that monitors that table.

Although trying to figure out why the service dies would be a better
solution.

andy
 
T

tshad

Michael Nemtsev said:
Hello tshad,

I'm not sure that such brutal way to fix you service is a good way :)
This is more of a bandaid until I figure out what the problem is.

Part of the problem may be that the program was originally written in VS
2002 and I heard there was some problem with services it built. I did
rebuild it in 2003 and it seems to work better, but I can't be sure yet.

I also am writing trace statements to a text file at various points in the
program to try an figure out what it does just before it dies (or appears to
die).
Why not to make some internal check, for example whether email was send or
not or for example each day in midnight restart service.

The first would be doable, but the 2nd wouldn't help. We can't wait for
possibly 12 hours for the reboot to take place as the emails wouldn't be
sent out in time.

The other problem would be how to start the same service on another server
if we determine that the program quits working (checking the email records
to see if they were sent as you suggest, for example). Not sure how to do
that yet.

Thanks,

Tom
 
T

tshad

Andy said:
On way would be to have teh service right to a db table every now and
then, and have another service that monitors that table.
That is what I may do in the mean time.
Although trying to figure out why the service dies would be a better
solution.

Am working on that now, but need a band aid at the moment.

Thanks,

Tom
 
M

Michael Nemtsev

Hello tshad,

Take into account that in some cases this isn't the solution, even if the
service status is in running status it may be hunged or smth

t> t>t> That was what I was looking for.
t>

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
T

tshad

Michael Nemtsev said:
Hello tshad,

Take into account that in some cases this isn't the solution, even if the
service status is in running status it may be hunged or smth

I agree.

I can do as was suggested about checking the DB to see if my emails were
sent. Since I know when the email records were written to the file, I can
do a check every 5 minutes or so to see if there are any email > 5 minutes
and if so, stop the service (even if it is hung - shouldn't hurt), then
start the service on a different service and send and email that this
process happened so we can restart the machine.

It would be nice to restart the machine remotely also (not sure how to do
that yet).

Thanks,

Tom
 
W

Willy Denoyette [MVP]

WMI and System.Management is what you need to look at.
See your other thread for a reply.

Willy.


| | > Hello tshad,
| >
| > Take into account that in some cases this isn't the solution, even if
the
| > service status is in running status it may be hunged or smth
|
| I agree.
|
| I can do as was suggested about checking the DB to see if my emails were
| sent. Since I know when the email records were written to the file, I can
| do a check every 5 minutes or so to see if there are any email > 5 minutes
| and if so, stop the service (even if it is hung - shouldn't hurt), then
| start the service on a different service and send and email that this
| process happened so we can restart the machine.
|
| It would be nice to restart the machine remotely also (not sure how to do
| that yet).
|
| Thanks,
|
| Tom
|
| >
| > t> | > t>
| >>> There's a ServiceController class, I'm pretty sure its in .Net 1.1
| >>> too.
| >>>
| > t> That was what I was looking for.
| > t>
| > ---
| > WBR,
| > Michael Nemtsev :: blog: http://spaces.msn.com/laflour
| >
| > "At times one remains faithful to a cause only because its opponents do
| > not cease to be insipid." (c) Friedrich Nietzsche
| >
| >
|
|
 

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