Boston2012 Posted January 9, 2013 Posted January 9, 2013 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. 'Option ExplicitOn Error Resume NextDim strNewContents, strLine, objFile,SuccessFile,strSuccessFlag,SuccessCode,strCritcalFlag,CriticalFileDim objShell,strOSSet objFSO = CreateObject("Scripting.FileSystemObject")Set objNetwork = CreateObject("WScript.Network")Set objShell = CreateObject("WScript.Shell")' ConstantsConst ForReading = 1Const ForWriting = 2Const ForAppending = 8strThisComputer = objNetwork.ComputerNamestrFileOutput = "C:\TJXLogs\" & KMSPing & "KMSPing.csv"strSuccessFlag = "C:\TJXLogs\Success.flag"strOS = objShell.ExpandEnvironmentStrings("Win32_OperatingSystem") 'Determine Operating Systemfor each objOS in GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")strOS=objOS.CaptionnextIf 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 IfIf objFSO.FileExists(strFileOutput) Then Set objOutputFile = objFSO.OpenTextFile (strFileOutput, ForWriting)Else Set objOutputFile = objFSO.CreateTextFile(strFileOutput, True)End IfIf Err <> 0 Then Wscript.Echo "Unable to open " & strFileOutput & " for output." WScript.QuitEnd IfIf objFSO.FileExists(strFileOutput) Then Set objOutputFile = objFSO.OpenTextFile (strFileOutput, ForWriting)Else Set objOutputFile = objFSO.CreateTextFile(strFileOutput, False)End IfstrTarget = "172.24.72.155" If Ping(strTarget) = True Then strResult = "True" set objsuccessflag = objFSO.CreateTextFile(strSuccessFlag, False)Else strResult = "False"End IfstrFileOutput = "C:\TJXLogs\" & KMSPing & "KMSPing.csv"Set objFSO = CreateObject("Scripting.FileSystemObject")objOutputFile.Write """" & strThisComputer & """,""" & StrOS & """,""" & strResult & """,""" & Now & """"& vbcrlfobjInFile.CloseobjOutFile.CloseFunction 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 IfEnd Function
gunsmokingman Posted January 9, 2013 Posted January 9, 2013 Try this, it should show a true or false message Dim Act :Set Act = CreateObject("Wscript.Shell") Dim Ip, Return :Ip ="127.0.0.1" '-> Local Address Return Yes Ping(Ip) If Return Then WScript.Echo Return & ", Ip Reply : " & Ip Else WScript.Echo Return & ", Ip Reply : " & Ip End If Function Ping(P) If Act.Run("Ping -n 1 -w 300 " & P, 0, True) = 0 Then Return = True Else Return = False End If End FunctionRename DemoPing.vbs.txt to DemoPing.vbs to make activeDemoPing.vbs.txt
Boston2012 Posted January 9, 2013 Author Posted January 9, 2013 Thanks for the reply. I'm still learning all this VB Scripting on the fly here, can you tell me where to add this data in my script? See below:
gunsmokingman Posted January 10, 2013 Posted January 10, 2013 I ment to try what I posted, the script you posted is a mess, so I want to start from scratch and confirm that you can get either tue or false returns.
Boston2012 Posted January 10, 2013 Author Posted January 10, 2013 Just tried it and it's not showing any message?
Boston2012 Posted January 10, 2013 Author Posted January 10, 2013 Correction just got a "False" Reply
gunsmokingman Posted January 10, 2013 Posted January 10, 2013 What IP Address did you use, that a default local adresss for the computerrunning the script.Here what I done so far Dim Act :Set Act = CreateObject("Wscript.Shell") Dim Os Dim Ip, Return :Ip ="127.0.0.1" '-> Local Address Return Yes GetOsName() Ping(Ip) If Return Then MsgBox Return & ", Ip Reply : " & Ip & vbCrLf & Os,4128, "Test Positive" Else WScript.Echo Return & ", Ip Reply : " & Ip,4128, "Test Negative" End If'-> Get Os Name Function GetOsName() For Each Obj in GetObject("winmgmts:").InstancesOf(_ "Win32_OperatingSystem") Os = Obj.Caption Next End Function'-> Ping Computer Function Ping(P) If Act.Run("Ping -n 1 -w 300 " & P, 0, True) = 0 Then Return = True Else Return = False End If End Function Ip True Ip False
DataCracker7899 Posted February 17, 2013 Posted February 17, 2013 ping it in batch just type@echo offcolor aclsping 123.456.789
submix8c Posted February 17, 2013 Posted February 17, 2013 (edited) PLEASE, DataCracker7899. The OP specifically asked for VBScript, not BAT!This is your "expertise" -CSS 1 CSS 2 CSS 3 JavaScript 1.1 - 1.8.5 Batch HTML 4 HTML 5 C++ MySQLStick with those topics. Edited February 17, 2013 by submix8c
jaclaz Posted February 17, 2013 Posted February 17, 2013 PLEASE, DataCracker7899. The OP specifically asked for VBScript, not BAT!This is your "expertise" -CSS 1 CSS 2 CSS 3 JavaScript 1.1 - 1.8.5 Batch HTML 4 HTML 5 C++ MySQLStick with those topics. Let me doubt about the "Batch" :jaclaz
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now