Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Ping Test

- - - - -

  • Please log in to reply
9 replies to this topic

#1
Boston2012

Boston2012
  • Member
  • 8 posts
  • Joined 26-October 12
  • OS:Server 2008 x86
  • Country: Country Flag
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 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



How to remove advertisement from MSFN

#2
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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 Function

Rename DemoPing.vbs.txt to DemoPing.vbs to make active
Attached File  DemoPing.vbs.txt   408bytes   5 downloads


GunSmokingMan



#3
Boston2012

Boston2012
  • Member
  • 8 posts
  • Joined 26-October 12
  • OS:Server 2008 x86
  • Country: Country Flag
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:

#4
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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.


GunSmokingMan



#5
Boston2012

Boston2012
  • Member
  • 8 posts
  • Joined 26-October 12
  • OS:Server 2008 x86
  • Country: Country Flag
Just tried it and it's not showing any message?

#6
Boston2012

Boston2012
  • Member
  • 8 posts
  • Joined 26-October 12
  • OS:Server 2008 x86
  • Country: Country Flag
Correction just got a "False" Reply

#7
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
What IP Address did you use, that a default local adresss for the computer
running 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 Attached File  Ip_True.png   45.17KB   14 downloads Ip FalseAttached File  Ip_False.png   36.82KB   9 downloads


GunSmokingMan



#8
DataCracker7899

DataCracker7899

    Newbie

  • Member
  • 15 posts
  • Joined 02-January 13
  • OS:Windows 7 x86
  • Country: Country Flag
ping it in batch just type
@echo off
color a
cls
ping 123.456.789
I am a professional programmer and plz email me and i will help you. my email is: andregoodarzi@hotmail.com i'm master in many programming languages and i can make websites too.


//AndreG7899
//DataCracker7899

#9
submix8c

submix8c

    Inconceivable!

  • Patrons
  • 4,371 posts
  • Joined 14-September 05
  • OS:none specified
  • Country: Country Flag
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++ MySQL

Stick with those topics. ;)

Edited by submix8c, 17 February 2013 - 11:12 AM.

Someday the tyrants will be unthroned... Jason "Jay" Chasteen; RIP, bro!

Posted Image


#10
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,654 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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++ MySQL

Stick with those topics. ;)

Let me doubt about the "Batch" :whistle: :
http://www.msfn.org/...-in-batch-file/

jaclaz




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users