Éric Moreau
asked on
Connected to the Internet?
I run applications on my laptop. I have features that are trying to send e-mails. When I am not connected to the Internet, I have to skip these parts.
How can I know for sure if I am connected to the Internet?
How can I know for sure if I am connected to the Internet?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
iboutchkine, when I try your code, I get the following exeption (on the line: Dim ret As Boolean = InternetGetConnectedState( e, 0))
An unhandled exception of type 'System.InvalidProgramExce ption' occurred in InternetConnection.exe
Additional information: Error: PInvoke item (field,method) must be Static.
An unhandled exception of type 'System.InvalidProgramExce
Additional information: Error: PInvoke item (field,method) must be Static.
<DllImport("wininet.dll")>
Public Function InternetGetConnectedState(
ByVal lpdwFlags As Integer, ByVal res As Integer) As Boolean
End Function
Public Function InternetConnectionExists()
' Determines if there is a connection to the Internet.
' Note that InternetGetConnectedState cannot be considered
' 100% reliable. An issue can occur if an internet connection
' has never been configured, the function may return true, even
' though there is no internet connection.
'
Dim e As Integer = 0
Dim ret As Boolean = InternetGetConnectedState(
Return ret
End Function