Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Internet Web Mail Stuff Code Examples

Determine if a machine is connected to the internet

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
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