Script for monitoring a Service

Discussion in 'MCSE' started by =?Utf-8?B?SmF2aWVy?=, Aug 3, 2007.

  1. 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?=, Aug 3, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?SmF2aWVy?=

    John R Guest

    "Javier" <> wrote in message
    news:...
    > 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, Aug 4, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a

    <script>alert();</script>

    =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a, Apr 13, 2004, in forum: Microsoft Certification
    Replies:
    0
    Views:
    7,869
    =?Utf-8?B?PHNjcmlwdD5hbGVydCgpOzwvc2NyaXB0Pg==?= a
    Apr 13, 2004
  2. Sidholaa108

    SERVICE PACK 2 +ABNORMALDISCONNECTION +SCRIPT ERROR

    Sidholaa108, Sep 12, 2004, in forum: Computer Support
    Replies:
    2
    Views:
    393
    Blinky the Shark
    Sep 12, 2004
  3. Hoss
    Replies:
    0
    Views:
    497
  4. nadiralishah
    Replies:
    0
    Views:
    1,200
    nadiralishah
    Jan 6, 2008
  5. Giuen
    Replies:
    0
    Views:
    1,154
    Giuen
    Sep 12, 2008
Loading...

Share This Page