Ping a server and restart services on a different server

Posted on 2008-10-07
Last Modified: 2010-04-24
I am trying to ping a server at a specified time period lets say from 10-11 am. If the ping is successful, I want to restart services on the current machine. If not successful to continue to ping. Here is what I have so far.  Can anyone tell me if I am on the right track or what else I need to complete.  

Dim strComputer

StrComputer = "."
Set objWMIService = GetObject(_
    "winmgmts:\\" & strComputer & "\root\cimv2")
strServiceName = "WZCSVC"
Set colPings = objWMIService.ExecQuery _
    ("Select * From Win32_PingStatus where Address = ''")

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_Service Where Name = '" & strServiceName & "'")

Do While i = 0
For Each objStatus in colPings
    If IsNull(objStatus.StatusCode) _
        or objStatus.StatusCode<>0 Then


    End If
Wscript.Sleep (6000)
Question by:earngreen
  • 2
LVL 67

Accepted Solution

sirbounty earned 500 total points
ID: 22666145
You're declaring the wmi reference twice...try this:
strServiceName = "WZCSVC"

IP = ""

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

Do While PingResult = False

  wscript.sleep 6000  


Set colItems = objWMIService.ExecQuery("Select * from Win32_Service Where Name = '" & strServiceName & "'")

For Each objService in colItems



Set objWMIService = Nothing

Function PingResult()

  On Error Resume Next

  Set colPings = objWMIService.ExecQuery ("Select * From Win32_PingStatus where Address = '" & IP & "'")

  For Each objStatus in colPings

    If IsNull(objStatus.StatusCode) or objStatus.StatusCode <> 0 Then 




    End If


End Function

Open in new window


Author Closing Comment

ID: 31503880
This works great. Thanks
LVL 67

Expert Comment

ID: 22668485
Happy to help - thanx for the grade! :^)

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now