469,282 Members | 1,732 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

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 15130
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Mike | last post: by
reply views Thread by Scott Davies | last post: by
3 posts views Thread by Doug Bailey | last post: by
4 posts views Thread by tshad | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.