This is get the information about the current network. If Internet is on, Connected to a modem. lan ect
What you need:
6 Text boxes or 6 labels.
In a module:
Option ExplicitPublic Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long' Local system uses a modem to connect to '' the Internet. 'Public Const INTERNET_CONNECTION_MODEM As Long = &H1' Local system uses a LAN to connect to t '' he Internet. 'Public Const INTERNET_CONNECTION_LAN As Long = &H2' Local system uses a proxy server to con '' nect to the Internet. 'Public Const INTERNET_CONNECTION_PROXY As Long = &H4' No longer used. 'Public Const INTERNET_CONNECTION_MODEM_BUSY As Long = &H8Public Const INTERNET_RAS_INSTALLED As Long = &H10Public Const INTERNET_CONNECTION_OFFLINE As Long = &H20Public Const INTERNET_CONNECTION_CONFIGURED As Long = &H40' InternetGetConnectedState wrapper funct '' ions
'
Public Function IsNetConnectViaLAN() As BooleanDim dwflags As Long' pass an empty varialbe into which the A '' PI will '' return the flags associated with the co '' nnection 'Call InternetGetConnectedState(dwflags, 0&)' return True if the flags indicate a LAN '' connection 'IsNetConnectViaLAN = dwflags And INTERNET_CONNECTION_LANEnd FunctionPublic Function IsNetConnectViaModem() As BooleanDim dwflags As Long' pass an empty varialbe into which the A '' PI will '' return the flags associated with the co '' nnection 'Call InternetGetConnectedState(dwflags, 0&)' return True if the flags indicate a mod '' em connection 'IsNetConnectViaModem = dwflags And INTERNET_CONNECTION_MODEMEnd FunctionPublic Function IsNetConnectViaProxy() As BooleanDim dwflags As Long' pass an empty varialbe into which the A '' PI will '' return the flags associated with the co '' nnection 'Call InternetGetConnectedState(dwflags, 0&)' return True if the flags indicate a pro '' xy connection 'IsNetConnectViaProxy = dwflags And INTERNET_CONNECTION_PROXYEnd FunctionPublic Function IsNetConnectOnline() As Boolean' no flags needed here - the API returns '' True '' if there is a connection of any type 'IsNetConnectOnline = InternetGetConnectedState(0&, 0&)End FunctionPublic Function IsNetRASInstalled() As BooleanDim dwflags As Long' pass an empty varialbe into which the A '' PI will '' return the flags associated with the co '' nnection 'Call InternetGetConnectedState(dwflags, 0&)' return True if the falgs include RAS in '' stalled 'IsNetRASInstalled = dwflags And INTERNET_RAS_INSTALLEDEnd FunctionPublic Function GetNetConnectString() As StringDim dwflags As LongDim msg As String' build a string for display 'If InternetGetConnectedState(dwflags, 0&) ThenIf dwflags And INTERNET_CONNECTION_CONFIGURED Thenmsg = msg & "You have a network connection configured." & vbCrLfEnd IfIf dwflags And INTERNET_CONNECTION_LAN Thenmsg = msg & "The local system connects to the Internet via a LAN"End IfIf dwflags And INTERNET_CONNECTION_PROXY Thenmsg = msg & ", and uses a proxy server. "Else: msg = msg & "."End IfIf dwflags And INTERNET_CONNECTION_MODEM Thenmsg = msg & "The local system uses a modem to connect to the Internet. "End IfIf dwflags And INTERNET_CONNECTION_OFFLINE Thenmsg = msg & "The connection is currently offline. "End IfIf dwflags And INTERNET_CONNECTION_MODEM_BUSY Thenmsg = msg & "The local system's modem is busy With a non-Internet connection. "End IfIf dwflags And INTERNET_RAS_INSTALLED Thenmsg = msg & "Remote Access Services are installed On this system."End IfElsemsg = "Not connected to the internet now."End If '{End Of}-> If InternetGetConnectedState(dwflags, 0&) ThenGetNetConnectString = msgEnd Function
In the form. I used text boxes for this example.
Option ExplicitPrivate Sub Command1_Click()Text1 = IsNetConnectViaLAN()Text2 = IsNetConnectViaModem()Text3 = IsNetConnectViaProxy()Text4 = IsNetConnectOnline()Text5 = IsNetRASInstalled()Text6 = GetNetConnectString()End Sub' End internet
That's it. The functions are pretty self explainitory on what they check for. Useful if you're making a downloader and want to make sure the user is connected to the internet.
No comments:
Post a Comment