-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckInternetConnectionModule.bas
137 lines (98 loc) · 3.73 KB
/
CheckInternetConnectionModule.bas
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
Attribute VB_Name = "CheckInternetConnectionModule"
'**************************************
' Name: Check internet connection type
' This code makes API calls to check for an internet conection and
' returns the type of connection through API calls to the wininet.dll
' By: Ayman Elbanhawy
'
' Inputs: None
'
' Returns: None
'
' Assumes: None
'
'Side Effects: None
'This code is copyrighted and has limited warranties.
'Please visit our site for an updated version of this code.
' http://www.imagineer-web.com/MasterKey/VB/connectionCheck.htm
'**************************************
'START .BAS MODULE CODE
Option Explicit
Public Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
'Internet connection VIA Proxy server.
Public Const ProxyConnection As Long = &H4
'Modem is busy.
Public Const ModemConnectionIsBusy As Long = &H8
'Internet connection is currently Offline
Public Const InternetIsOffline As Long = &H20
'Internet connection is currently configured
Public Const InternetConnectionIsConfigured As Long = &H40
'Internet connection VIA Modem.
Public Const ModemConnection As Long = &H1
'Remote Access Server is installed.
Public Const RasInstalled As Long = &H10
'Internet connection VIA LAN.
Public Const LanConnection As Long = &H2
Public Function IsLanConnection() As Boolean
Dim dwflags As Long
'return True if LAN connection
Call InternetGetConnectedState(dwflags, 0&)
IsLanConnection = dwflags And LanConnection
End Function
Public Function IsModemConnection() As Boolean
Dim dwflags As Long
'return True if modem connection.
Call InternetGetConnectedState(dwflags, 0&)
IsModemConnection = dwflags And ModemConnection
End Function
Public Function IsProxyConnection() As Boolean
Dim dwflags As Long
'return True if connected through a proxy.
Call InternetGetConnectedState(dwflags, 0&)
IsProxyConnection = dwflags And ProxyConnection
End Function
Public Function IsConnected() As Boolean
'Returns true if there is any internet connection.
IsConnected = InternetGetConnectedState(0&, 0&)
End Function
Public Function IsRasInstalled() As Boolean
Dim dwflags As Long
'return True if RAS installed.
Call InternetGetConnectedState(dwflags, 0&)
IsRasInstalled = dwflags And RasInstalled
End Function
Public Function ConnectionTypeMsg() As String
Dim dwflags As Long
Dim msg As String
'Return Internet connection msg.
If InternetGetConnectedState(dwflags, 0&) Then
If dwflags And InternetConnectionIsConfigured Then
msg = msg & "Internet connection is configured." & vbCrLf
End If
If dwflags And LanConnection Then
msg = msg & "Internet connection via a LAN"
End If
If dwflags And ProxyConnection Then
msg = msg & ", and connection is through a proxy server."
Else
msg = msg & "."
End If
If dwflags And ModemConnection Then
msg = msg & "Internet connection via a Modem"
End If
If dwflags And InternetIsOffline Then
msg = msg & "Internet connection is currently offline."
End If
If dwflags And ModemConnectionIsBusy Then
msg = msg & "Modem is busy with a non-Internet connection."
End If
If dwflags And RasInstalled Then
msg = msg & "Remote Access Services are installed on local system."
End If
Else
msg = "You are currently not connected to the internet."
End If
ConnectionTypeMsg = msg
End Function
' END MODULE CODE
'##############################