Click here to Skip to main content
15,559,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In lan, there have 5 nodes connected & password not refered to every node after start the m/c & same OS(Windows XP Service pack 3) install in each m/c.But I will get VB-6.0 codes from internet and run this code, not read the value of remote registry key from other node m/c.
I try & try this problem, but can't solve.
How can i solve this problem???
Plz Plz supply to me right vb-6.0/vb.net coding ...

------------------------------------------------

This following vb6.0 Code is below :
VB
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 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)
    lRetVal = RegOpenKeyEx(hRemoteReg, _
        "SOFTWARE\Tech", 0, KEY_QUERY_VALUE, hKey)
        
    If lRetVal <> ERROR_SUCCESS Then
        MsgBox "Cannot open key"
    Else
        sValue = String(255, " ")
        lRetVal = RegQueryValueExString(hKey, _
            "Name", 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

Private Sub Form_Load()
Dim lRet As Long
    'Connect to the remote registry
    lRet = RegConnectRegistry("\\main", _
                              HKEY_LOCAL_MACHINE, _
                              hRemoteReg)
    
    If (lRet = ERROR_SUCCESS) Then
        MsgBox "Successfully connected to remote registry"
    Else
        MsgBox "Error:" & 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
Posted
Updated 30-Sep-11 22:03pm
v2

1 solution

Have you ever heard about WMI (Windows Management Instrumentation)? That is one of the easiest way to access the registry in a different machine. Actually almost all the resources on a remote machine.

Also you can use RegistryKey.OpenRemoteBaseKey method.

http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.openremotebasekey.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900