Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Ping to Website using VB6.0

Visual Basic 4 / 5 / 6

  • Please log in to reply
4 replies to this topic

#1 gyswamy

gyswamy

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 17 April 2011 - 08:09 PM

Hi All,

I want to know How to Ping Website using VB6.0 programing with code? I am searching since 10 days in google. I have not got any code so far. Please help me if any one knows.

Thanks in Advance.:cursing:
  • 0

#2 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 18 April 2011 - 08:54 AM

From this webpage:
Ping from VB6 - VBForums

They suggest this code:
Public Function ComputerIsOnline(ByVal strComputerName As String) As Boolean
    On Error GoTo ErrorHandler
    
    Dim strResult   As String
    Dim ShellX      As String
    Dim FileNum     As Integer
    Dim lPid        As Long
    Dim lHnd        As Long
    Dim lRet        As Long
    
    'DoEvents
    ShellX = Shell("command.com /c ping -n 2 " & strComputerName & " > log.txt", vbHide)
    lPid = ShellX
    If lPid <> 0 Then
        lHnd = OpenProcess(SYNCHRONIZE, 0, lPid)
        If lHnd <> 0 Then
            lRet = WaitForSingleObject(lHnd, INFINITE)
            CloseHandle (lHnd)
        End If
        FileNum = FreeFile
        Open "log.txt" For Input As #FileNum
        strResult = Input(LOF(1), 1)
        Close #FileNum
        ComputerIsOnline = (InStr(strResult, "Lost = 0") > 0)
    End If
    Exit Function
ErrorHandler:
    ComputerIsOnline = False
    Exit Function
End Function
or this:
Private Declare Function GetRTTAndHopCount _
    Lib "iphlpapi.dll" _
   (ByVal lDestIPAddr As Long, _
    ByRef lHopCount As Long, _
    ByVal lMaxHops As Long, _
    ByRef lRTT As Long) As Long
        
Private Declare Function inet_addr _
    Lib "wsock32.dll" _
   (ByVal cp As String) As Long
 
 

Public Function Ping(prmIPaddr As String) As Boolean
Dim IPaddr As Long, HopsCount As Long, RTT As Long
Dim MaxHops As Long
    Const SUCCESS = 1
    MaxHops = 20               ' should be enough ...
    IPaddr = inet_addr(prmIPaddr)
    Ping = (GetRTTAndHopCount(IPaddr, HopsCount, MaxHops, RTT) = SUCCESS)
End Function

Give one of those a try and see if it works.
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid


#3 gyswamy

gyswamy

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 18 April 2011 - 05:22 PM

Thanks for Reply,

I am beginer in VB6.0. I used your code in my example.but it's showing compile error at "Synchronize" variable not defined..So Should we add any reference to project? And I have one doubt in that program what is that mean --

Public Function ComputerIsOnline(ByVal strComputerName As String) As Boolean

This is Function you are using..here you are sending computername as argument..But i want to ping to one website like "google.com". So Can i pass "google.com" in place of this argument?
I am waithing for your replay..

Thank you..:w00t:
  • 0

#4 Mark Wylde

Mark Wylde

    CC Regular

  • Member
  • PipPipPip
  • 47 posts

Posted 19 April 2011 - 03:27 AM

Define the variable at the top of your code:
Const SYNCHRONIZE = &H100000

I think you should be able to use an IP address or host name in that function anyway. Shouldn't make much difference.
  • 0

#5 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 19 April 2011 - 05:20 AM

The ComputerIsOnline function is just someone else's version of the ping function. The name of the function is not important. You should be able to pass in a URL to the function for strComputerName with no problems. I'm not fluent in VB, but I just wanted to post what I found from searching in case it helps.
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download