Solved

Ping a server and restart services on a different server

Posted on 2008-10-07
3
291 Views
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 = '255.255.255.0'")

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

    Else
        objItem.StartService(strServiceName)

    End If
Next
Wscript.Sleep (6000)
loop
0
Comment
Question by:earngreen
  • 2
3 Comments
 
LVL 67

Accepted Solution

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

IP = "255.255.255.0"
 

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

Do While PingResult = False

  wscript.sleep 6000  

Loop
 

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

For Each objService in colItems

  objService.StartService()

Next
 

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 

      PingResult=False

    Else

      PingResult=True

    End If

  Next

End Function

Open in new window

0
 

Author Closing Comment

by:earngreen
Comment Utility
This works great. Thanks
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Happy to help - thanx for the grade! :^)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

7 Experts available now in Live!

Get 1:1 Help Now