Declare Function RegConnectRegistry Lib "advapi32.dll" _ Alias "RegConnectRegistryA" _ (ByVal lpMachineName As String, _ ByVal hKey As Long, _ phkResult As Long) As Long
RegConnectRegistry устанавливает соединение с заданным ключом реестра на другом компьютере. Не работает с компьютером под управлением Windows XP Home Edition
В случае успеха функция возвращает ERROR_SUCCESS, в случае ошибки - код ошибки
HKEY_CLASSES_ROOT |
HKEY_CURRENT_USER |
HKEY_LOCAL_MACHINE |
HKEY_PERFORMANCE_DATA |
HKEY_USERS |
' Получим доступ к реестру удаленного компьютера
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_ALL_ACCESS = &H3F
Private Const REG_SZ As Long = 1
Private Const ERROR_SUCCESS = 0&
Private Declare Function RegConnectRegistry Lib "advapi32.dll" _
Alias "RegConnectRegistryA" _
(ByVal lpMachineName As String, _
ByVal hKey As Long, _
phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" _
Alias "RegOpenKeyExA" _
(ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
phkResult As Long) As Long
Private Declare Function RegQueryValueExString Lib "advapi32.dll" _
Alias "RegQueryValueExA" _
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
lpType As Long, _
ByVal lpData As String, _
lpcbData As Long) As Long
Private hRemoteReg As Long
Private Sub Form_Load()
Dim lRet As Long
' Соединяемся с удаленным реестром. Замените имя компьютера на реальное имя
lRet = RegConnectRegistry("\\RemoteMachineName", _
HKEY_LOCAL_MACHINE, _
hRemoteReg)
If (lRet = ERROR_SUCCESS) Then
MsgBox "Связь с удаленным реестром успешно установлена"
Else
MsgBox "Ошибка:" & Err.LastDllError
Unload Me
Exit Sub
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim lRet As Long
If hRemoteReg <> 0 Then
lRet = RegCloseKey(hRemoteReg)
End If
End Sub
Private Sub Command1_Click()
Dim lRetVal As Long
Dim hKey As Long
Dim sValue As String
lRetVal = RegOpenKeyEx(hRemoteReg, _
"HARDWARE\DESCRIPTION\System", 0, KEY_QUERY_VALUE, hKey)
If lRetVal <> ERROR_SUCCESS Then
MsgBox "Cannot open key"
Else
sValue = String(255, " ")
lRetVal = RegQueryValueExString(hKey, _
"SystemBIOSVersion", 0&, REG_SZ, sValue, 255)
If lRetVal <> ERROR_SUCCESS Then
MsgBox "Cannot query value"
Else
MsgBox sValue
End If
lRetVal = RegCloseKey(hKey)
If lRetVal <> ERROR_SUCCESS Then
MsgBox "Cannot close key"
End If
End If
End Sub