473,473 Members | 2,303 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 15894
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 to start the service back up example: ...
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 do the following: - Select remote server -...
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...
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 in which to achive the same thing? Glenn
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...
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...
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 service, and in the creation method, i've created...
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 running, I need to start the service. Also it would...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.