By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

Check if a Windows service running

P: n/a
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
Aug 9 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
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

tWhat would be a good way to check programmatically whether a service
twas running?
t>
tWe have a service that dies periodically and I need to check to see
tif this service is running. I know how to check to see if the status
tis in stopped or running mode. But that doesn't tell me if it is
tactually running.
t>
tI need to know this so that if it happens I can programmatically
tstart the same service on another machine.
t>
tWhat I would like to do is build a service that just periodically
tchecks (about once a minute) to see if the other service is actually
trunning.
t>
tThanks,
t>
tTom
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
Aug 9 '06 #2

P: n/a
"Michael Nemtsev" <ne*****@msn.comwrote in message
news:9c**************************@msnews.microsoft .com...
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
tWhat would be a good way to check programmatically whether a service
twas running?
ttWe have a service that dies periodically and I need to check to see
tif this service is running. I know how to check to see if the status
tis in stopped or running mode. But that doesn't tell me if it is
tactually running.
ttI need to know this so that if it happens I can programmatically
tstart the same service on another machine.
ttWhat I would like to do is build a service that just periodically
tchecks (about once a minute) to see if the other service is actually
trunning.
ttThanks,
ttTom
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


Aug 9 '06 #3

P: n/a
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"Michael Nemtsev" <ne*****@msn.comwrote in message
tnews:9c**************************@msnews.microsof t.com...
t>
>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.
tI am the author of the service.
t>
tBut I have a service that sends out emails that shows in running mode
tand for some reason it dies once every 5 or 6 days and seems to be
tfrozen (could be in an infinite loop - but I can't find where that
twould happen). The status in the services windows or when I request
tit from another program shows it as running (which would make sense
tif it never hit the Stop code.
t>
tI need to find a good way to monitor it to tell if it has stopped or
tnot (until I can find the problem with the code).
t>
tBTW, when I get to this point, I can't stop the program at all. I
tneed to reboot the server to get it released.
t>
>The only way to check whether it run is to check that
files/environment that service control
tNot sure what you mean here.
t>
tThanks,
t>
tTom
t>
>tWhat would be a good way to check programmatically whether a
service
twas running?
ttWe have a service that dies periodically and I need to check to
see
tif this service is running. I know how to check to see if the
status
tis in stopped or running mode. But that doesn't tell me if it is
tactually running.
ttI need to know this so that if it happens I can
programmatically
tstart the same service on another machine.
ttWhat I would like to do is build a service that just
periodically
tchecks (about once a minute) to see if the other service is
actually
trunning.
ttThanks,
ttTom
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
---
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
Aug 9 '06 #4

P: n/a
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

tshad wrote:
"Michael Nemtsev" <ne*****@msn.comwrote in message
news:9c**************************@msnews.microsoft .com...
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
tWhat would be a good way to check programmatically whether a service
twas running?
ttWe have a service that dies periodically and I need to check to see
tif this service is running. I know how to check to see if the status
tis in stopped or running mode. But that doesn't tell me if it is
tactually running.
ttI need to know this so that if it happens I can programmatically
tstart the same service on another machine.
ttWhat I would like to do is build a service that just periodically
tchecks (about once a minute) to see if the other service is actually
trunning.
ttThanks,
ttTom
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
Aug 9 '06 #5

P: n/a
"Michael Nemtsev" <ne*****@msn.comwrote in message
news:9c**************************@msnews.microsoft .com...
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"Michael Nemtsev" <ne*****@msn.comwrote in message
tnews:9c**************************@msnews.microsof t.com...
t>
>>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.
tI am the author of the service.
ttBut I have a service that sends out emails that shows in running
mode
tand for some reason it dies once every 5 or 6 days and seems to be
tfrozen (could be in an infinite loop - but I can't find where that
twould happen). The status in the services windows or when I request
tit from another program shows it as running (which would make sense
tif it never hit the Stop code.
ttI need to find a good way to monitor it to tell if it has stopped or
tnot (until I can find the problem with the code).
ttBTW, when I get to this point, I can't stop the program at all. I
tneed to reboot the server to get it released.
t>
>>The only way to check whether it run is to check that
files/environment that service control
tNot sure what you mean here.
ttThanks,
ttTom
t>
>>tWhat would be a good way to check programmatically whether a
service
twas running?
ttWe have a service that dies periodically and I need to check to
see
tif this service is running. I know how to check to see if the
status
tis in stopped or running mode. But that doesn't tell me if it is
tactually running.
ttI need to know this so that if it happens I can
programmatically
tstart the same service on another machine.
ttWhat I would like to do is build a service that just
periodically
tchecks (about once a minute) to see if the other service is
actually
trunning.
ttThanks,
ttTom
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
---
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


Aug 9 '06 #6

P: n/a
"Andy" <aj*****@alum.rit.eduwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
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
>
andy

tshad wrote:
>"Michael Nemtsev" <ne*****@msn.comwrote in message
news:9c**************************@msnews.microsof t.com...
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
tWhat would be a good way to check programmatically whether a service
twas running?
ttWe have a service that dies periodically and I need to check to
see
tif this service is running. I know how to check to see if the
status
tis in stopped or running mode. But that doesn't tell me if it is
tactually running.
ttI need to know this so that if it happens I can programmatically
tstart the same service on another machine.
ttWhat I would like to do is build a service that just periodically
tchecks (about once a minute) to see if the other service is actually
trunning.
ttThanks,
ttTom
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


Aug 9 '06 #7

P: n/a
There's a ServiceController class, I'm pretty sure its in .Net 1.1 too.

Andy

tshad wrote:
"Andy" <aj*****@alum.rit.eduwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
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
Aug 10 '06 #8

P: n/a
"Andy" <aj*****@alum.rit.eduwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
There's a ServiceController class, I'm pretty sure its in .Net 1.1 too.
That was what I was looking for.

Thanks,

Tom
>
Andy

tshad wrote:
>"Andy" <aj*****@alum.rit.eduwrote in message
news:11**********************@b28g2000cwb.googleg roups.com...
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

Aug 10 '06 #9

P: n/a
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"Andy" <aj*****@alum.rit.eduwrote in message
tnews:11**********************@i42g2000cwa.googleg roups.com...
t>
>There's a ServiceController class, I'm pretty sure its in .Net 1.1
too.
tThat 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
Aug 10 '06 #10

P: n/a
"Michael Nemtsev" <ne*****@msn.comwrote in message
news:9c**************************@msnews.microsoft .com...
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"Andy" <aj*****@alum.rit.eduwrote in message
tnews:11**********************@i42g2000cwa.googleg roups.com...
t>
>>There's a ServiceController class, I'm pretty sure its in .Net 1.1
too.
tThat 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


Aug 10 '06 #11

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

Willy.
"tshad" <ts**********@ftsolutions.comwrote in message
news:OA*************@TK2MSFTNGP06.phx.gbl...
| "Michael Nemtsev" <ne*****@msn.comwrote in message
| news:9c**************************@msnews.microsoft .com...
| 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"Andy" <aj*****@alum.rit.eduwrote in message
| tnews:11**********************@i42g2000cwa.googleg roups.com...
| t>
| >>There's a ServiceController class, I'm pretty sure its in .Net 1.1
| >>too.
| >>>
| tThat 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
| >
| >
|
|
Aug 11 '06 #12

P: n/a
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:OH****************@TK2MSFTNGP06.phx.gbl...
WMI and System.Management is what you need to look at.
See your other thread for a reply.
Looking at that now.

Thanks,

Tom
>
Willy.
"tshad" <ts**********@ftsolutions.comwrote in message
news:OA*************@TK2MSFTNGP06.phx.gbl...
| "Michael Nemtsev" <ne*****@msn.comwrote in message
| news:9c**************************@msnews.microsoft .com...
| 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"Andy" <aj*****@alum.rit.eduwrote in message
| tnews:11**********************@i42g2000cwa.googleg roups.com...
| t>
| >>There's a ServiceController class, I'm pretty sure its in .Net 1.1
| >>too.
| >>>
| tThat 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
| >
| >
|
|


Aug 11 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.