473,382 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Check if a Windows service running

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
12 14485
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
"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
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
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
"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
"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
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
"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
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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brad Jones | last post by:
Hello, I'm hoping someone can give me some help or guidance here. I'm not sure if this is even the best group to post to for this. Our OEM equipment's software architecture relies heavily on a...
7
by: Mike | last post by:
I want to create a windows service that will monitor another window service. what i need for the service to do is, if a service is stopped I need it to start the service back up example: ...
2
by: Chris Podmore | last post by:
I don't know if this is the correct newsgroup but I couldn't find one for Windows Services Is it possible to check that a Windows Service is still running from another machine The idea being a...
3
by: Doug Bailey | last post by:
I am trying to control a Windows Service via a Web Service interface. (I am developing in .NET2003) I am using the ServiceController object which allows me to read the state of the services with...
5
by: Tony | last post by:
Every 10 seconds I need to search a SQL table for orders to print. The orders are created through WebForms on ASP.NET clients. The orders should not print until 10 minutes before they are due. ...
2
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app...
7
by: Joris De Groote | last post by:
Hi, can vb check if a windows service is running or not? ( Webclient ) Thanks Joris
4
by: tshad | last post by:
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...
12
by: Shadlan | last post by:
Hi. I need to know if a service is running on my server. Is there any PHP instruction that I can use to do this?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.