Results 1 to 10 of 21
Thread: Making a windows service
-
- Join Date
- 11-13-07
- Location
- Plano, TX and Ruston, LA
- Posts
- 32,364
- Post Thanks / Like
- Blog Entries
- 43
02-06-13, 07:54 PM #1Making a windows service
There's a long running problem with the software used to control the music my station plays over the air. Namely, two services either stop running or hang. This causes the computer to lose access to the internet; no other computer on the network is affected. Restarting the program fixes the issue.
My question is would it be possible to write code to make a constantly running windows service that would check the states of those faulty services and restart them when needed? Or, would it be better to just write a little program that would sit in the systray? What language would I write it in?
The non-duck tape solution would be to install the music program correctly (whoever did that borked it), and to first install a 64 bit OS on the computer (it's a 64bit system, but the same person who borked the install of the program put a 32 bit system on it...he's a comp sci major..soooo -_-). Unfortunately, this would require us to pay for install time that would cost a few grand. So...it ain't gonna happen soon.enf-Jesus its been like 12 minutes and you're already worried about stats?! :-P
Bigdog-Sweet home Alabama you are an idiot.
-
-
- Join Date
- 11-13-07
- Location
- Plano, TX and Ruston, LA
- Posts
- 32,364
- Post Thanks / Like
- Blog Entries
- 43
-
-
- Join Date
- 11-13-07
- Location
- Plano, TX and Ruston, LA
- Posts
- 32,364
- Post Thanks / Like
- Blog Entries
- 43
02-06-13, 08:40 PM #5Re: Making a windows service
I'll find out the services' names.
As for query interval, I'm not sure. The services generally only stop once a day. Maybe once every hour then?enf-Jesus its been like 12 minutes and you're already worried about stats?! :-P
Bigdog-Sweet home Alabama you are an idiot.
-
02-07-13, 08:12 AM #6
Re: Making a windows service
Here's the basis for the script ... It's powershell so you will need that installed if it's not.
Interval is set to 5 seconds but you can change to whatever..
I can make you an established GUI that's easy to use if you provide me with the service names
While ($True)
{
#Service 1
$ServiceName1 = Get-Service | Where-Object {$_.Name -eq "VDS"}
if ($ServiceName1.Status -eq "Stopped")
{
Start-Service -Name "VDS"
}
Get-Service | Where-Object {$_.Name -eq "VDS"}
#Service 2
$ServiceName2 = Get-Service | Where-Object {$_.Name -eq "VDS"}
if ($ServiceName2.Status -eq "Stopped")
{
Start-Service -Name "VDS"
}
Get-Service | Where-Object {$_.Name -eq "VDS"}
Sleep -seconds (5)
}Last edited by Warprosper; 02-07-13 at 08:14 AM.
-
-
-
02-08-13, 12:21 PM #9
Re: Making a windows service
You could combine that with tellin it to automatically restart every XX hours :P Say 18 hours if it typically makes it a day before hanging? The dedicated kiosks I set up I have scripts i run that restart the computers at specified times to make sure they get updates and that no services are hanging. Saves me a service call.
-
02-08-13, 12:30 PM #10
Re: Making a windows service
Here's the GUI script ... 2 timers... One for querying the service to give you time to manually restart it the other is to have the script start it....Final function is for the restart button.. Green/Red icon indicators let you know status... and you can't see this here but it runs in the systray with balloon notifications instead of running in the taskbar..
function OnApplicationLoad {
return $true
}
function OnApplicationExit {
$script:ExitCode = 0
}
$Form_Load={
}
#ServiceQueryTimer
$Timerq = New-Object System.Windows.Forms.Timer
$Timerq.Interval = 5000 # (5 Seconds)
$Timerq.add_Tick({QueryServices})
$Timerq.start()
#ServiceStartTimer
$Timer = New-Object System.Windows.Forms.Timer
$Timer.Interval = 200000 # (2 Minutes)
$Timer.add_Tick({ServicesStart})
$Timer.start()
function ServicesStart
{
#Service 1
$ServiceName1 = Get-Service | Where-Object {$_.Name -eq "VDS"}
if ($ServiceName1.Status -eq "Stopped")
{
$Color.BackColor = 'Red'
Start-Service -Name "VDS"
}
else {$Color.BackColor = 'Green'}
#Service 2
$ServiceName2 = Get-Service | Where-Object {$_.Name -eq "PLA"}
if ($ServiceName2.Status -eq "Stopped")
{
$Button1.BackColor = 'Red'
Start-Service -Name "PLA"
}
else {$Button1.BackColor = 'Green'}
}
function QueryServices
{
$ServiceName1 = Get-Service | Where-Object {$_.Name -eq "VDS"}
if ($ServiceName1.Status -eq "Stopped")
{
$Color.BackColor = 'Red'
}
else {$Color.BackColor = 'Green'}
$ServiceName2 = Get-Service | Where-Object {$_.Name -eq "PLA"}
if ($ServiceName2.Status -eq "Stopped")
{
$Button1.BackColor = 'Red'
}
else {$Button1.BackColor = 'Green'}
}
$StartServices_Click={
#TODO: Place custom script here
Start-Service -Name "VDS"
Start-Service -Name "PLA"
ServicesStart
}Last edited by Warprosper; 02-08-13 at 12:32 PM.
Alundil, Phyrelight liked this post
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks