Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Ping a server and restart services on a different server

Posted on 2008-10-07
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 67

Accepted Solution

sirbounty earned 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

722 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