hi Experts,
i am not so good on VB Script. I have created a ping tool in VB Script.
1. pings to Google .com with a greater Count saves the Output file
2. meanwhile opens that file, checks for String "Minimum and Percent"
3. if Found will Display the whole line Containing "Minimum and Percent" both
4. or else close all Files and Again search the same strings.
No output is Displayed in Msgbox . pl help with Code....
here is My code:
-----------------------------------------------------------------'
Option Explicit
Sub fnl()
Dim i
i = Shell("\windows\system32\cmd.exe", vbNormalFocus)
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate "C:\Windows\system32\cmd.exe"
Application.Wait (Now + TimeValue("0:00:02"))
objShell.SendKeys "[/COLOR][COLOR=#417394]ping google.com -n 10 > D:\Report\percent.txt{ENTER}"
' Script to copy just certain lines from a text file.
' and place in another text file
' Experts Exchange Rob Sampson
' Version 1.1 - June 23 2009
' -----------------------------------------------------------------
Dim strFileName, strString1, strString2
Dim objFSO, objFile, strLine
Dim objOutputFile
strFileName = "D:\Report\percent.txt"
strString1 = "Packets"
strString2 = "Minimum"
[Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set objFile = objFSO.OpenTextFile(strFileName, ForReading, False)
While Not objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine, strString1) > 0 And InStr(strLine, strString2) > 0 Then RunCode
Wend
objFile.Close
End Sub
Sub RunCode()
Dim pkt, rndtrip, myFile, text, textline
Dim Final As Integer
myFile = "D:\Report\percent.txt"
Final = FreeFile()
Open myFile For Input As #Final
Do Until EOF(Final)
Line Input #Final, textline
text = text & textline
Loop
Close #Final
pkt = Trim(Mid(text, InStr(text, "Packets") + 0, (InStrRev(text, "Losst") + 0) - (InStr(text, "Packets") + 1)))
rndtrip = Trim(Mid(text, InStr(text, "Minimum") + 0, (InStrRev(text, "ms") + 0) - (InStr(text, "Minimum") + 1)))
Call MsgBox("Percent : " & pkt & " Round-Trip : " & rndtrip & ".", vbOKOnly)
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate "C:\Windows\system32\cmd.exe"
Application.Wait (Now + TimeValue("0:00:02"))
objShell.SendKeys "exit{ENTER}"
End Sub