borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (ASP programming problem and need help)Next Topic (Default web browser) New Topic New Poll Post Reply
AndreaVB Forum : Internet Applications : Detect internet connection
Poster Message
Massoud
Level: Guest


icon Detect internet connection

Hello everyone !

I want to know how we can find out that if the computer
is connected to the Internrt or not ?

Reagrds.

20-05-2004 at 03:47 PM
| Quote Reply
BRMC
Level: VB Lord


Registered: 28-11-2003
Posts: 210
icon Re: Detect internet connection

Add a command button to your form, and place the following code in the General Declarations section:


Private Sub Command1_Click()
If ActiveConnection = True Then
  MsgBox "You have an active connection.", vbInformation
Else
  MsgBox "You have no active connections.", vbInformation
End If
End Sub


Next, add the following code to a module


Option Explicit

Public Const ERROR_SUCCESS = 0&
Public Const APINULL = 0&
Public Const HKEY_LOCAL_MACHINE = &H80000002

Public ReturnCode As Long

Declare Function RegCloseKey Lib "advapi32.dll" (ByVal _
hKey As Long) As Long

Declare Function RegOpenKey Lib "advapi32.dll" Alias _
"RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As _
String, phkResult As Long) As Long

Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName _
As String, ByVal lpReserved As Long, lpType As Long, _
lpData As Any, lpcbData As Long) As Long

Public Function ActiveConnection() As Boolean
    Dim hKey As Long
    Dim lpSubKey As String
    Dim phkResult As Long
    Dim lpValueName As String
    Dim lpReserved As Long
    Dim lpType As Long
    Dim lpData As Long
    Dim lpcbData As Long
    ActiveConnection = False
    lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
    ReturnCode = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, _
    phkResult)
    
    If ReturnCode = ERROR_SUCCESS Then
        hKey = phkResult
        lpValueName = "Remote Connection"
        lpReserved = APINULL
        lpType = APINULL
        lpData = APINULL
        lpcbData = APINULL
        ReturnCode = RegQueryValueEx(hKey, lpValueName, _
        lpReserved, lpType, ByVal lpData, lpcbData)
        lpcbData = Len(lpData)
        ReturnCode = RegQueryValueEx(hKey, lpValueName, _
        lpReserved, lpType, lpData, lpcbData)
        
        If ReturnCode = ERROR_SUCCESS Then
            If lpData = 0 Then
                ActiveConnection = False
            Else
                ActiveConnection = True
            End If
        End If
        RegCloseKey (hKey)
    End If
End Function


[Edited by JLRodgers on 20-05-2004 at 10:08 AM GMT]

____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell

20-05-2004 at 04:03 PM
View Profile Send Email to User Show All Posts | Quote Reply
Massoud
Level: Guest

icon Re: Detect internet connection


Thanks BRMC.

The function worked well.

Have a nice day !  

20-05-2004 at 10:09 PM
| Quote Reply
AndreaVB Forum : Internet Applications : Detect internet connection
Previous Topic (ASP programming problem and need help)Next Topic (Default web browser) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder