473,795 Members | 3,439 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 15939
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
3940
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
3691
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
6903
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
4185
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
9353
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
3142
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
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10164
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
10001
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...
0
9042
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.