472,353 Members | 1,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Checking that a Windows Service is running and restarting if stopped

My software relies on a third party data provider to a propretary database.

In turn the third party database relies on a Windows Service that runs on
the server to supply the data... The problem is that from time to time this
service dies without warning.

Is there any way that I can write another small service or similar (using
vb.net) that checks at regular intervals that the service is running and
restart it if it isn't???

Can I check that the service is running by searching for the service
executable in the process list? or is there an easier way? What do I need
to code to start the service?

Thanks in advance

Simon

Nov 21 '05 #1
4 15680
This will get you started, but make sure you add a reference to
System.ServiceProcess.
Dim services() As System.ServiceProcess.ServiceController

Dim i As Integer

services = System.ServiceProcess.ServiceController.GetService s()

For i = 0 To services.Length - 1

If services(i).ServiceName = "Wibble" Then

If services(i).Status = ServiceControllerStatus.Stopped Then

services(i).Start()

End If

End If

Next
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
My software relies on a third party data provider to a propretary
database.

In turn the third party database relies on a Windows Service that runs on
the server to supply the data... The problem is that from time to time
this service dies without warning.

Is there any way that I can write another small service or similar (using
vb.net) that checks at regular intervals that the service is running and
restart it if it isn't???

Can I check that the service is running by searching for the service
executable in the process list? or is there an easier way? What do I
need to code to start the service?

Thanks in advance

Simon

Nov 21 '05 #2
Spot on!!

Exactly what I was after.

Thanks :)

Simon
"JohnFol" <Ou************@WibbleObbble.Com> wrote in message
news:BQ****************@newsfe3-win.ntli.net...
This will get you started, but make sure you add a reference to
System.ServiceProcess.
Dim services() As System.ServiceProcess.ServiceController

Dim i As Integer

services = System.ServiceProcess.ServiceController.GetService s()

For i = 0 To services.Length - 1

If services(i).ServiceName = "Wibble" Then

If services(i).Status = ServiceControllerStatus.Stopped Then

services(i).Start()

End If

End If

Next
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
My software relies on a third party data provider to a propretary
database.

In turn the third party database relies on a Windows Service that runs on
the server to supply the data... The problem is that from time to time
this service dies without warning.

Is there any way that I can write another small service or similar
(using vb.net) that checks at regular intervals that the service is
running and restart it if it isn't???

Can I check that the service is running by searching for the service
executable in the process list? or is there an easier way? What do I
need to code to start the service?

Thanks in advance

Simon


Nov 21 '05 #3
Simon,
In addition to JohnFol's example, I normally simply create the
ServiceController directly, without using the ServiceController.GetServices
method.

Dim service As New ServiceController("Wibble")
service.Refresh()
If service.Status = ServiceControllerStatus.Stopped Then
service.Start()
End If

If I had the above in a loop, I would consider using
ServiceController.WaitForStatus, instead.

service.Refresh()
service.WaitForStatus(ServiceControllerStatus.Stop ped)
service.Start()

Then I would consider including the timeout (TimeSpan) parameter to
WaitForStatus so as to allow a controlled exit from WaitForStatus...

Hope this helps
Jay
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
| My software relies on a third party data provider to a propretary
database.
|
| In turn the third party database relies on a Windows Service that runs on
| the server to supply the data... The problem is that from time to time
this
| service dies without warning.
|
| Is there any way that I can write another small service or similar (using
| vb.net) that checks at regular intervals that the service is running and
| restart it if it isn't???
|
| Can I check that the service is running by searching for the service
| executable in the process list? or is there an easier way? What do I
need
| to code to start the service?
|
| Thanks in advance
|
| Simon
|
|
|
Nov 21 '05 #4
Thanks for that Jay.. thats exactly what I'm after
Regards
Simon
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Simon,
In addition to JohnFol's example, I normally simply create the
ServiceController directly, without using the
ServiceController.GetServices
method.

Dim service As New ServiceController("Wibble")
service.Refresh()
If service.Status = ServiceControllerStatus.Stopped Then
service.Start()
End If

If I had the above in a loop, I would consider using
ServiceController.WaitForStatus, instead.

service.Refresh()
service.WaitForStatus(ServiceControllerStatus.Stop ped)
service.Start()

Then I would consider including the timeout (TimeSpan) parameter to
WaitForStatus so as to allow a controlled exit from WaitForStatus...

Hope this helps
Jay
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
| My software relies on a third party data provider to a propretary
database.
|
| In turn the third party database relies on a Windows Service that runs
on
| the server to supply the data... The problem is that from time to time
this
| service dies without warning.
|
| Is there any way that I can write another small service or similar
(using
| vb.net) that checks at regular intervals that the service is running and
| restart it if it isn't???
|
| Can I check that the service is running by searching for the service
| executable in the process list? or is there an easier way? What do I
need
| to code to start the service?
|
| Thanks in advance
|
| Simon
|
|
|

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
0
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to...
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...
2
by: Glenn | last post by:
Hello Is it possible to pass arguements to a .net service once it is in a running state. If this is not possible , are they alternative ways...
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...
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...
6
by: sergio.calleja | last post by:
Hi Everybody, i need to restart a windows service made with c# when an fixed event is raised. So to test it, I've added a servicecontroller to my...
3
by: John Wright | last post by:
I need to know how to check the state of a windows service. I need to determine if the windows service "Smart Card" is running. If it is not...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.