rosalinda
asked on
How can my application detect if i am connected to the internet, and what method i use to connect.(Modem or LAN) ?
Dear experts,Hi.
I need a VB program that is able to detedct if i am connected to the internet or not and by Modem or LAN ?(IMMEDIATELY)
I 've searched lots of sites for that and found lots of codes for that . All of the codes owners have claimed their codes work well. but i 've tested all of them and each has some problems .
for example those ones that have used wininet, if you are not connected to the internet tells that you are connected to the internet via LAN.
I dont want to use pinging method .
I need a VB program that is able to detedct if i am connected to the internet or not and by Modem or LAN ?(IMMEDIATELY)
I 've searched lots of sites for that and found lots of codes for that . All of the codes owners have claimed their codes work well. but i 've tested all of them and each has some problems .
for example those ones that have used wininet, if you are not connected to the internet tells that you are connected to the internet via LAN.
I dont want to use pinging method .
but why don't you use InetIsOffline?
returns true if offline or not yet made a connect attempt, false if connected.
returns true if offline or not yet made a connect attempt, false if connected.
ASKER
Dear mcoop
when i am disconnected,pinging causes to appear dialup connection dialogbox and i don't want that.
do you have any solution for this problem?
when i am disconnected,pinging causes to appear dialup connection dialogbox and i don't want that.
do you have any solution for this problem?
ASKER
Dear Belfry ,
Can you give me more details about using InetIsOffline?
How can i use it in my code?Please write for me.
Can you give me more details about using InetIsOffline?
How can i use it in my code?Please write for me.
ASKER
Dear Belfry ,
Can you give me more details about using InetIsOffline?
How can i use it in my code?Please write for me.
Can you give me more details about using InetIsOffline?
How can i use it in my code?Please write for me.
Ok, first declare it
'assume it's declared in a form
Private Declare Function InetIsOffline Lib "url.dll" (ByVal dwFlags As Long) As Long
then use it somewhere, e.g:
Private Sub Form_Load()
dim bIsOnLine as Boolean
bIsOnLine=Not InetIsOffline()
if bIsOnLine then
'tell the user that he's currently online
else
'tell the user that he's not yet connected to the internet
end if
End Sub
:)
'assume it's declared in a form
Private Declare Function InetIsOffline Lib "url.dll" (ByVal dwFlags As Long) As Long
then use it somewhere, e.g:
Private Sub Form_Load()
dim bIsOnLine as Boolean
bIsOnLine=Not InetIsOffline()
if bIsOnLine then
'tell the user that he's currently online
else
'tell the user that he's not yet connected to the internet
end if
End Sub
:)
oops, sorry, i missed a paramter for InetIsOffline
...
Dim bIsOnLine as Boolean
bIsOnLine=Not InetIsOffline(0)'the parameter must be 0
...
...
Dim bIsOnLine as Boolean
bIsOnLine=Not InetIsOffline(0)'the parameter must be 0
...
ASKER
Dear Belfry ,
I don't know why but It always says "you are online".
I don't know why but It always says "you are online".
Two functions from my Internet Module (not done with it, why you can't download it yet).
Declares:
Private Declare Function InternetAttemptConnect Lib "wininet.dll" (ByVal dwReserved As Long) As Long
Private Declare Function InternetGetConnectedStateE x Lib "wininet.dll" Alias "InternetGetConnectedState ExA" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Long, ByVal dwReserved As Long) As Long
Private Const INTERNET_CONNECTION_MODEM = &H1&
Private Const INTERNET_CONNECTION_LAN = &H2&
Private Const INTERNET_CONNECTION_PROXY = &H4&
Private Const INTERNET_RAS_INSTALLED = &H10&
Private Const INTERNET_CONNECTION_OFFLIN E = &H20&
Private Const INTERNET_CONNECTION_CONFIG URED = &H40&
Functions:
Public Function canAttempt() As Boolean
canAttempt = IIf(InternetAttemptConnect (ByVal 0&) = 0, True, False)
End Function
Public Function Connection() As Boolean
Dim dwFlags As Long
Dim sNameBuf As String, msg As String
Dim lPos As Long
sNameBuf = String$(513, 0)
If (InternetGetConnectedState Ex(dwFlags , sNameBuf, 512, 0&)) Then
'Yes, you have active connection
'Collect ExtraInfo:
'lPos = InStr(sNameBuf, vbNullChar)
'If lPos > 0 Then sConnectionName = Left$(sNameBuf, lPos - 1)
'ConnectionInfo = dwFlags
'Now ConnectionInfo variable contain OR'ed INTERNET_ flags (see constants above)
'You can extract info you need with And keyford:
If (dwFlags And INTERNET_CONNECTION_LAN) Then
Connection = True
'MsgBox "Your connection use LAN"
ElseIf (dwFlags And INTERNET_CONNECTION_MODEM) Then
Connection = True
'MsgBox "Your connection use Modem"
End If
Else
Connection = False
'MsgBox = "Your computer is NOT connected to Internet"
End If
End Function
Downside of this code, Network (lan) users can always connect.
The Connection() returns whether or not it CAN connect.
The canAttempt() returns whether or not it is able to connect (login to the internet), this is useful for modem users so you can tell IF they've denied dialing.
Best first to see if you CAN connect with the canAttempt() function and if you can, see if you ARE connected with the Connection() function (WILL return true IF a modem user has a default dialup and has enabled dial on demand).
Should be enough to help.
Declares:
Private Declare Function InternetAttemptConnect Lib "wininet.dll" (ByVal dwReserved As Long) As Long
Private Declare Function InternetGetConnectedStateE
Private Const INTERNET_CONNECTION_MODEM = &H1&
Private Const INTERNET_CONNECTION_LAN = &H2&
Private Const INTERNET_CONNECTION_PROXY = &H4&
Private Const INTERNET_RAS_INSTALLED = &H10&
Private Const INTERNET_CONNECTION_OFFLIN
Private Const INTERNET_CONNECTION_CONFIG
Functions:
Public Function canAttempt() As Boolean
canAttempt = IIf(InternetAttemptConnect
End Function
Public Function Connection() As Boolean
Dim dwFlags As Long
Dim sNameBuf As String, msg As String
Dim lPos As Long
sNameBuf = String$(513, 0)
If (InternetGetConnectedState
'Yes, you have active connection
'Collect ExtraInfo:
'lPos = InStr(sNameBuf, vbNullChar)
'If lPos > 0 Then sConnectionName = Left$(sNameBuf, lPos - 1)
'ConnectionInfo = dwFlags
'Now ConnectionInfo variable contain OR'ed INTERNET_ flags (see constants above)
'You can extract info you need with And keyford:
If (dwFlags And INTERNET_CONNECTION_LAN) Then
Connection = True
'MsgBox "Your connection use LAN"
ElseIf (dwFlags And INTERNET_CONNECTION_MODEM)
Connection = True
'MsgBox "Your connection use Modem"
End If
Else
Connection = False
'MsgBox = "Your computer is NOT connected to Internet"
End If
End Function
Downside of this code, Network (lan) users can always connect.
The Connection() returns whether or not it CAN connect.
The canAttempt() returns whether or not it is able to connect (login to the internet), this is useful for modem users so you can tell IF they've denied dialing.
Best first to see if you CAN connect with the canAttempt() function and if you can, see if you ARE connected with the Connection() function (WILL return true IF a modem user has a default dialup and has enabled dial on demand).
Should be enough to help.
rosalinda:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
Experts: Post your closing recommendations! Who deserves points here?
rosalinda, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:
Save as PAQ -- No Refund.
DanRollins -- EE database cleanup volunteer
Moderator, my recommended disposition is:
Save as PAQ -- No Refund.
DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the result is the result