Visual Basic > Internet Web Mail Stuff
Determine if a machine is connected to the internet
Determine if a machine is connected to the internet The following code demonstrates how to determine if a machine is connected to the internet (+ how the machine is connected). Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias "InternetGetConnectedStateExA" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Long, ByVal dwReserved As Long) As Boolean Public Enum eConnectionType INTERNET_CONNECTION_MODEM = &H1& INTERNET_CONNECTION_LAN = &H2& INTERNET_CONNECTION_PROXY = &H4& INTERNET_RAS_INSTALLED = &H10& INTERNET_CONNECTION_OFFLINE = &H20& INTERNET_CONNECTION_CONFIGURED = &H40& End Enum 'Purpose : Determines basic information regarding the local machine's internet connection state. 'Inputs : sConnectionName See outputs. ' eType See outputs. 'Inputs : Returns True if connected + ' sConnectionName The name of the internet connection ' eType The type of internet connection (see eConnectionType) 'Notes : Public Property Get InternetConnected(Optional ByRef sConnectionName As String, Optional ByRef eType As eConnectionType) As Boolean Dim sConNameBuffer As String * 513 Dim lPos As Long 'Clear output values sConnectionName = "" eType = 0 'Call API InternetConnected = InternetGetConnectedStateEx(eType, sConNameBuffer, 512, 0&) 'Clean up output lPos = InStr(sConNameBuffer, vbNullChar) If lPos > 0 Then sConnectionName = Left$(sConNameBuffer, lPos - 1) End If End Property 'Test routine Private Sub Form_Load() Dim eType As eConnectionType Dim sName As String 'Determine whether we have a connection: If InternetConnected(sName, eType) Then MsgBox "Connected to internet using '" & sName & "' ", vbInformation Else MsgBox "Not connected to internet ", vbInformation End If End Sub
Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows