新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Boolean
Private Enum Flags
'Local system uses a LAN to connect to the Internet.
INTERNET_CONNECTION_LAN = &H2
'Local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM = &H1
'Local system uses a proxy server to connect to the Internet.
INTERNET_CONNECTION_PROXY = &H4
'Local system has RAS installed.
INTERNET_RAS_INSTALLED = &H10
End Enum
Private Sub Command1_Click()
Dim lngFlags As Long
If InternetGetConnectedState(lngFlags, 0) Then
'connected.
If lngFlags And Flags.INTERNET_CONNECTION_LAN Then
'LAN connection.
MsgBox ("LAN connection.")
ElseIf lngFlags And Flags.INTERNET_CONNECTION_MODEM Then
'Modem connection.
MsgBox ("Modem connection.")
ElseIf lngFlags And Flags.INTERNET_CONNECTION_PROXY Then
'Proxy connection.
MsgBox ("Proxy connection.")
End If
Else
'not connected.
MsgBox ("Not connected.")
End If
End Sub