Go Back   Velocity Reviews > Newsgroups > MCSE
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

MCSE - Script for monitoring a Service

 
Thread Tools Search this Thread
Old 08-03-2007, 09:50 PM   #1
Default Script for monitoring a Service


I've been working almost three months on a script, it starts the service when
I executed it, but I need a script that runs all the time and checks the
service status, like a endless loop. the language I'm using it's VBscript,
this is the code. besides all I wanna do is that this script check the
service status every 1 milisecond and if the service is stopped then the
script starts the service.

Option Explicit
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, strService, intSleep
strComputer = "."
intSleep = 1000


strService = " 'Messenger' "
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from
Win32_Service Where State = 'Stopped' and Name = 'Messenger'")

For Each objService in colListOfServices

WSCript.Sleep intSleep
objService.StartService()
Next
WScript.Echo "Your "& strService & " service has Started"
WScript.Quit
' End of Example WMI script to Start / Stop services


=?Utf-8?B?SmF2aWVy?=
  Reply With Quote
Old 08-04-2007, 12:57 PM   #2
John R
 
Posts: n/a
Default Re: Script for monitoring a Service

"Javier" <> wrote in message
news:8CB56AF0-9383-4F61-B01A-...
> I've been working almost three months on a script, it starts the service
> when
> I executed it, but I need a script that runs all the time and checks the
> service status, like a endless loop. the language I'm using it's VBscript,
> this is the code. besides all I wanna do is that this script check the
> service status every 1 milisecond and if the service is stopped then the
> script starts the service.
>
> Option Explicit
> Dim objWMIService, objItem, objService
> Dim colListOfServices, strComputer, strService, intSleep
> strComputer = "."
> intSleep = 1000
>
>
> strService = " 'Messenger' "
> Set objWMIService = GetObject("winmgmts:" &
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colListOfServices = objWMIService.ExecQuery ("Select * from
> Win32_Service Where State = 'Stopped' and Name = 'Messenger'")
>
> For Each objService in colListOfServices
>
> WSCript.Sleep intSleep
> objService.StartService()
> Next
> WScript.Echo "Your "& strService & " service has Started"
> WScript.Quit
> ' End of Example WMI script to Start / Stop services


You do know about the options on the 'recovery' tab on the service
properties?

John R




John R
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Novice needs help with Adserver.Adtech.de CPU Rookie General Help Related Topics 3 05-10-2008 05:54 PM
Am new here and need help with virus/spyware cm punk General Help Related Topics 1 11-13-2006 11:04 AM
Trojan Horse! AHHH! okstatefan@swbell.net A+ Certification 11 02-08-2005 07:12 PM
Re: High Gasoline Prices Create A+ Service Opportunities Frederic A+ Certification 3 01-17-2004 11:38 PM
Re: Home service calls Ghost A+ Certification 3 07-24-2003 10:36 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46