i want to find out if the computer that my program is running,
is connected to the internet!

i tried this code that i found here,
but it shows that i'm always online, which is false,
cuz i unplug my connection

here's the code:

VB Code:
  1. Private Const INTERNET_OPEN_TYPE_DIRECT = 1
  2. Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000
  3.  
  4. Private Declare Function InternetOpen Lib "wininet.dll" _
  5. Alias "InternetOpenA" _
  6. (ByVal lpszAgent As String, _
  7. ByVal dwAccessType As Long, _
  8. ByVal lpszProxyName As String, _
  9. ByVal lpszProxyBypass As String, _
  10. ByVal dwFlags As Long) As Long
  11.  
  12. Private Declare Function InternetCloseHandle Lib "wininet.dll" _
  13. (ByVal hEnumHandle As Long) As Long
  14.  
  15. Public Function InternetConnectOpen() As Boolean
  16.  
  17. Dim hInternet As Long
  18.  
  19. InternetConnectOpen = False
  20. hInternet = InternetOpen("Vb FTP Transfer", INTERNET_OPEN_TYPE_DIRECT, _
  21. vbNullString, vbNullString, INTERNET_FLAG_NO_CACHE_WRITE)
  22.  
  23. If hInternet > 0 Then InternetConnectOpen = True
  24. Call InternetCloseHandle(hInternet)
  25.  
  26. hInternet = 0
  27.  
  28. End Function
  29.  
  30. Private Sub Command1_Click()
  31. If InternetConnectOpen Then
  32.     MsgBox "online"
  33. Else
  34.     MsgBox "offline"
  35. End If
  36. End Sub