Script for monitoring a Service
 




IT Certification FAQ

 
|
Home
|
Microsoft
|
CISCO
|
CompTIA
|
Exam/Study FAQ
|
Employment FAQ
| Links  | Forums  |
Book Reviews


FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  ProfileProfile  Log in to check your private messagesPrivate messages  Log inLog in

Script for monitoring a Service

 
Post new topic   Reply to topic    Forum Index -> microsoft.public.cert.exam.mcse
Author Message
Javier
Guest





PostPosted: Sat Aug 04, 2007 1:50 am    Post subject: Script for monitoring a Service Reply with quote

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
Back to top
John R
Guest





PostPosted: Sat Aug 04, 2007 4:57 pm    Post subject: Re: Script for monitoring a Service Reply with quote

"Javier" <Javier@discussions.microsoft.com> wrote in message
news:8CB56AF0-9383-4F61-B01A-754F8BC84C02@microsoft.com...
Quote:
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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> microsoft.public.cert.exam.mcse All times are GMT
Page 1 of 1

 

Copyright © 2002-2006 Web-S-Sense Pty. Ltd. All rights reserved.

Powered by phpBB
Advertising | Policies/Disclaimers | Contact us | Link to us


Featured Sites: Free Antivirus and Antispyware Info | Free PC Support | MCSE Directory