Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleSee if the system is connected to the network using the registry
DescriptionThis example shows how to see if the system is connected to the network using the registry in Visual Basic 6. It looks for a connection entry in a RemoteAccess registry key and determines whether its Connection value is non-zero.
KeywordsRAS, network, connected, connection
CategoriesSoftware Engineering
 
Open the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\RemoteAccess registry key and see if the Remote Connection value is non-zero.

If this key does not exist, you cannot use this method.

 
Private Sub Form_Load()
Dim hKey As Long
Dim value(1 To 256) As Byte
Dim length As Long
Dim value_type As Long
Dim txt As String

    lblConnected.Caption = "Error"

    ' Open the key.
    If RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
        "System\CurrentControlSet\Services\RemoteAccess", _
        0&, KEY_ALL_ACCESS, hKey) <> ERROR_SUCCESS _
    Then
        MsgBox "Error opening key."
        Exit Sub
    End If
    
    ' Get the subkey's value.
    length = 256
    If RegQueryValueEx(hKey, "Remote Connection", _
        0&, value_type, value(1), length) _
            <> ERROR_SUCCESS _
    Then
        MsgBox "Error getting subkey value."
    Else
        ' Convert the binary value into a string value.
        txt = Format$(Hex$(value(1)), "00 ") & _
              Format$(Hex$(value(2)), "00 ") & _
              Format$(Hex$(value(3)), "00 ") & _
              Format$(Hex$(value(4)), "00")
        lblConnection.Caption = txt

        If value(1) = 0 And value(2) = 0 And value(3) = 0 _
            And value(4) = 0 Then
            lblConnected.Caption = "Not connected"
        Else
            lblConnected.Caption = "Connected"
        End If
    End If

    ' Close the key.
    If RegCloseKey(hKey) <> ERROR_SUCCESS Then
        MsgBox "Error closing key."
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated