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 |