(¯`·.¸¸.-=[ WebTime ]=-.¸¸.·´¯) <jhdata@adr.dk> skrev i en
nyhedsmeddelelse:Ny8H6.3849$Iq.465886@news101.telia.com...
> 'If you are designing a project which can use an Internet connection,
> 'it can be useful to know whether the system is connected or not. There
are
> various methods of doing this,
> 'however the most informative and reliable method is to use the
WinInet.DLL
> 'InternetGetConnectedStateEx() API call. The only problem with this call
is
> it is only implemented for the WinInet.DLL
> 'version shipped with Internet Explorer version 4.0 or higher.
When somebody installs my program, can't I just make the installation
install the wininet.dll too... or is there so many files, that it would be
easier installing IE4?
Anyway... thanks a lot for the code (it works great, if you declare the
dll-function as Private instead of Public)!
- Bjarke Walling
> 'To test out this function, start a new project and add the following
code:
>
> 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
>
>
>
> 'To try out the code, add a CommandButton and a Multi-Line TextBox to your
> test project's
> 'main form. Then add the following code to try the function:
>
>
> Private Sub Command1_Click()
> Dim eR As EIGCInternetConnectionState
> Dim sMsg As String
> Dim sName As String
> Dim bConnected As Boolean
>
> ' 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
>
> 'Run the project. When you click the command button, the text box will be
> updated with the status
> 'of the current connection, the name of RAS dial-up connection used (if
> applicable) and also various
> 'information about how the connection is being achieved (i.e. by modem or
> LAN, via a proxy and whether
> 'the connection is configured or not).
> --------------------------------------------------------------------------
--
> ------------------------------
> Hilsen
http://webtime.adr.dk
> --------------------------------------------------------------------------
--
> ------------------------------
> "Bjarke Walling Petersen" <bwp@bwp.dk> skrev i en meddelelse
> news:9ceo1e$u6u$1@news.cybercity.dk...
> > Hej...
> >
> > Er der nogen der ved hvordan man i VB checker om man er på internettet.
> Før
> > hen har jeg brugt WinSock til at finde IP-adressen og kontrolleret om
den
> > var 127.0.0.1 (i så fald gik jeg ud fra at computeren ikke var på
> > internettet)...
> > Men jeg har fundet ud af at man ikke behøver at have ip 127.0.0.1,
selvom
> > man ikke er på internettet.
> > Hvad gør man?
> >
> > - Bjarke Walling
> >
> >
>
>