473,847 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
+ 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 15954
This will get you started, but make sure you add a reference to
System.ServiceP rocess.
Dim services() As System.ServiceP rocess.ServiceC ontroller

Dim i As Integer

services = System.ServiceP rocess.ServiceC ontroller.GetSe rvices()

For i = 0 To services.Length - 1

If services(i).Ser viceName = "Wibble" Then

If services(i).Sta tus = ServiceControll erStatus.Stoppe d Then

services(i).Sta rt()

End If

End If

Next
"Simon Verona" <ne**@aphrodite uk.com> wrote in message
news:%2******** *******@tk2msft ngp13.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.C om> wrote in message
news:BQ******** ********@newsfe 3-win.ntli.net...
This will get you started, but make sure you add a reference to
System.ServiceP rocess.
Dim services() As System.ServiceP rocess.ServiceC ontroller

Dim i As Integer

services = System.ServiceP rocess.ServiceC ontroller.GetSe rvices()

For i = 0 To services.Length - 1

If services(i).Ser viceName = "Wibble" Then

If services(i).Sta tus = ServiceControll erStatus.Stoppe d Then

services(i).Sta rt()

End If

End If

Next
"Simon Verona" <ne**@aphrodite uk.com> wrote in message
news:%2******** *******@tk2msft ngp13.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
ServiceControll er directly, without using the ServiceControll er.GetServices
method.

Dim service As New ServiceControll er("Wibble")
service.Refresh ()
If service.Status = ServiceControll erStatus.Stoppe d Then
service.Start()
End If

If I had the above in a loop, I would consider using
ServiceControll er.WaitForStatu s, instead.

service.Refresh ()
service.WaitFor Status(ServiceC ontrollerStatus .Stopped)
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**@aphrodite uk.com> wrote in message
news:%2******** *******@tk2msft ngp13.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******** ********@tk2msf tngp13.phx.gbl. ..
Simon,
In addition to JohnFol's example, I normally simply create the
ServiceControll er directly, without using the
ServiceControll er.GetServices
method.

Dim service As New ServiceControll er("Wibble")
service.Refresh ()
If service.Status = ServiceControll erStatus.Stoppe d Then
service.Start()
End If

If I had the above in a loop, I would consider using
ServiceControll er.WaitForStatu s, instead.

service.Refresh ()
service.WaitFor Status(ServiceC ontrollerStatus .Stopped)
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**@aphrodite uk.com> wrote in message
news:%2******** *******@tk2msft ngp13.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
712
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: service 1 - my service watches service 2 - windows service service 2 is stopped - service 1 starts service 2
0
3946
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 - Select from two specific services - Check the status of the server
3
3693
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 no problems. However, I am not able to start or stop the service unless I go through the process of impersonating an administrative user. (See MSDN KB 306158) Since it appears to be a privilege issue, I set the folders in IIS holding the Web...
2
2771
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
6904
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 (which is the UI used to adjust the actions taken by, and the schedule of the service), then a privileged user thread should be used in the UI - no service required. But... "A windows service enables the creation of long-running executable
4
4191
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 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.
6
9359
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 a new thread to try to stop it. This is my code: public Service1() { // This call is required by the Windows.Forms Component Designer.
3
3144
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 be nice to set it to automatic so I wouldn't have to keep checking. Anyone know how to start a service from VB.NET code? I want to put the check and service activation in my program startup module. Thanks. John
0
9889
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10652
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10709
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10343
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7885
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7058
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5914
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4535
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 we have to send another system
3
3166
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.