I would like a vbscript to ping an IP at certain time intervals (seconds ideally) and email me if the pings timeout. So far I have gotten the following code which runs the windows ping.exe, but the script completes and sends an email before the ping times out. The problem is in the switch I have on the ping command as you'll see below.
I am using this to ping a router on the other side of a VPN, so I will receive an email when the VPN disconnects. A combination vbscript and batch file would work as well.
Rem Runs Ping command, outputs results to text file.
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DriveType = 3")
For Each objItem in colItems
strDriveLetter = objItem.DeviceID
strCommand = "ping 192.xxx.x.xxx -w 999"
Set objExecObject = objShell.Exec(strCommand)
Do While Not objExecObject.StdOut.AtEndOfStream
strResults = objExecObject.StdOut.ReadAll()
strText = strText & strResults
Rem Sends email alert
Set objFile = objFSO.CreateTextFile("C:\PingFailed.txt")
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "VPN_Dissconnect@domain.com"
objEmail.To = "email@example.com"
objEmail.Subject = "VPN from office to RemoteSite just disconnected"
objEmail.Textbody = "The ping time from the Office to RemoteSite was just over 999ms, indicating the VPN probably disconnected." & strDate
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
Rem Renames text file with time and date