Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: VB 6 and IsDestinationReachable API


Message #1 by "dan caron" <dancaron@w...> on Thu, 23 May 2002 22:41:58
Hi all, 

I need to run a VB program from the Win 2000 Pro system and determine if 
the Win 2000 Server machine is (un)reachable. Maybe my approach is wrong. 
Here goes.

I have a Win2k Server with sp2, Win2k Pro with sp2 and visual basic 6(sp5)

The network is very simple, the 2 computers above connected to a 5 port D-
Link Hub. 

My problem: If I pull the network cable from the machine running Win2k 
Pro, code below will detect each and every time when the Win2k Server is 
unreachable or reachable once I plug the cable back in. If I pull the 
network cable off the Win2k Server machine or simply ShutDown the Win2k 
Server the program never detects the Server is no longer available. Why?

Any help would be greatly appreciated!

Code below:

**************** in a module ****************
Const NETWORK_ALIVE_AOL = &H4
Const NETWORK_ALIVE_LAN = &H1
Const NETWORK_ALIVE_WAN = &H2

Public Declare Function IsDestinationReachable Lib _
  "Sensapi.dll" Alias "IsDestinationReachableA" _
  (ByVal lpszDestination As String, _
  lpQOCInfo As QOCINFO) As Long

Public Type QOCINFO
  dwSize As Long
  dwFlags As Long
  dwInSpeed As Long
  dwOutSpeed As Long
End Type

**************** in a Form ******************
Private Sub Command2_Click()
Dim strPing As String
strPing = "192.168.1.3"
Call Ping(strPing)

End Sub

Public Function Ping(ByVal IP As String) As Boolean
  Dim QuestStruct As QOCINFO
  Dim lReturn As Long

  ' determine length of return
  QuestStruct.dwSize = Len(QuestStruct)

  ' test to see if address reachable
  lReturn = IsDestinationReachable(IP, QuestStruct)
  
  ' is reachable
  If lReturn = 1 Then
    Ping = True
  Else
    Ping = False
  End If
End Function

  Return to Index