看看如下代码:
检测是否以联网及联网方式
module:
Public 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 Long
Public Enum EIGCInternetConnectionState
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
Public Property Get InternetConnected( _
Optional ByRef eConnectionInfo As EIGCInternetConnectionState, _
Optional ByRef sConnectionName As String _
) As Boolean
Dim dwFlags As Long
Dim sNameBuf As String
Dim Lr As Long
Dim iPos As Long
sNameBuf = String$(513, 0)
Lr = InternetGetConnectedStateEx(dwFlags, sNameBuf, 512, 0&)
eConnectionInfo = dwFlags
iPos = InStr(sNameBuf, vbNullChar)
If iPos > 0 Then
sConnectionName = Left$(sNameBuf, iPos - 1)
ElseIf Not sNameBuf = String$(513, 0) Then
sConnectionName = sNameBuf
End If
InternetConnected = (Lr = 1)
End Property
窗体中
Private Sub Form_Load()
' Determine whether we have a connection:
bConnected = InternetConnected(Er, sName)
' The connection state info parameter provides details
' about how we connect:
If (Er And INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM Then
sMsg = sMsg & "Connection uses a modem." & vbCrLf
End If
If (Er And INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN Then
sMsg = sMsg & "Connection uses LAN." & vbCrLf
End If
If (Er And INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY Then
sMsg = sMsg & "Connection is via Proxy." & vbCrLf
End If
If (Er And INTERNET_CONNECTION_OFFLINE) = INTERNET_CONNECTION_OFFLINE Then
sMsg = sMsg & "Connection is Off-line." & vbCrLf
End If
If (Er And INTERNET_CONNECTION_CONFIGURED) = INTERNET_CONNECTION_CONFIGURED Then
sMsg = sMsg & "Connection is Configured." & vbCrLf
Else
sMsg = sMsg & "Connection is Not Configured." & vbCrLf
End If
If (Er And INTERNET_RAS_INSTALLED) = INTERNET_RAS_INSTALLED Then
sMsg = sMsg & "System has RAS installed." & vbCrLf
End If
' Display the connection name and info:
If bConnected Then
Text1.Text = "Connected: " & sName & vbCrLf & vbCrLf & sMsg
Else
Text1.Text = "Not Connected: " & sName & vbCrLf & vbCrLf & sMsg
End If
End Sub
(本贴加为精华,以示鼓励——LucasLynn)
[此贴子已经被LucasLynn于2006-6-9 11:05:05编辑过]
|