Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PING TEST

Status
Not open for further replies.

Boston2012

Technical User
Nov 8, 2012
17
US
Below is copy of script I'm using, the .csv file that shows results is showing "False" and should be showing "True". Any ideas why this is happening? I am able to manually ping 172.24.72.155 and getting replies.

' Purpose: Key Management Service (KMS) Ping Test.
' Project: SS101015
' Author: S. Johnson, TJX Store Systems Software Management
' Initial Date: 10/29/2012
' Version: 1.0
'**Start Encode**

'Option Explicit
On Error Resume Next

Dim strNewContents, strLine, objFile,SuccessFile,strSuccessFlag,SuccessCode,strCritcalFlag,CriticalFile
Dim objShell,strOS
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")

' Constants
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

strThisComputer = objNetwork.ComputerName
strFileOutput = "C:\TJXLogs\" & KMSPing & "KMSPing.csv"
strSuccessFlag = "C:\TJXLogs\Success.flag"
strOS = objShell.ExpandEnvironmentStrings("Win32_OperatingSystem")

'Determine Operating System

for each objOS in GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
strOS=objOS.Caption
next

If LCase(strOS) = RTrim(LCase("Microsoft Windows 2000 Server")) Then
strOS = "Windows 2000"
ElseIf LCase(strOS) = Rtrim(LCase("Microsoft Windows Server 2008 Standard")) Then
strOS = "Windows 2008"
Else
strOS = "Windows 2008"
End If


If objFSO.FileExists(strFileOutput) Then
Set objOutputFile = objFSO.OpenTextFile (strFileOutput, ForWriting)
Else
Set objOutputFile = objFSO.CreateTextFile(strFileOutput, True)
End If

If Err <> 0 Then
Wscript.Echo "Unable to open " & strFileOutput & " for output."
WScript.Quit
End If

If objFSO.FileExists(strFileOutput) Then
Set objOutputFile = objFSO.OpenTextFile (strFileOutput, ForWriting)
Else
Set objOutputFile = objFSO.CreateTextFile(strFileOutput, False)
End If


strTarget = "172.24.72.155"
If Ping(strTarget) = True Then
strResult = "True"
set objsuccessflag = objFSO.CreateTextFile(strSuccessFlag, False)
Else
strResult = "False"
End If

strFileOutput = "C:\TJXLogs\" & KMSPing & "KMSPing.csv"



Set objFSO = CreateObject("Scripting.FileSystemObject")
objOutputFile.Write """" & strThisComputer & """,""" & StrOS & """,""" & strResult & """,""" & Now & """"& vbcrlf
objInFile.Close
objOutFile.Close

Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else

Ping = False
End If

End Function
 
are you sure the command is returning a value? I ran into this and used .Exec instead and looked for "Reply" in the output. The only issue is that a window is displayed :/

Code:
function ping(strComputer)
	ping = false
	set objShell = CreateObject("WScript.Shell")
	set objExec = objShell.Exec("%comspec% /c ping.exe " & strComputer & " -n 1 -w 100 -4")
	do until objExec.Stdout.AtEndOfStream
		strLine = objExec.StdOut.ReadLine
		if (inStr(strLine, "Reply")) then
			ping = true
			exit do
		end if
	loop
end function

-Geates

 
Or
Code:
[blue]Function Ping(strComputer)
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set objPing = objWMIService.ExecQuery("Select * From Win32_PingStatus Where Address = '" & strComputer)
    For Each objStatus In objPing
        Ping = objStatus.StatusCode = 0
    Next
End Function[/blue]
 
strongm, I presume you meant this:
Set objPing = objWMIService.ExecQuery("Select * From Win32_PingStatus Where Address = '" & strComputer[tt][!] & "'"[/!][/tt])

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes to both. Cutting and pasting from a somewhat more complex VB example lost something in the translation ...
 
Good evening,

Thanks for the assistance it appears to be doing what I need. Thanks!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top