Solved

Ping a server and restart services on a different server

Posted on 2008-10-07
3
323 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
[X]
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
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 22666145
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
ID: 31503880
This works great. Thanks
0
 
LVL 67

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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