从远程节点读取注册表值 [英] Registry Value Read from Remote Node

查看:89
本文介绍了从远程节点读取注册表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在局域网中,有5个连接的节点&启动m/c&之后,并非每个节点都引用密码.每个m/c中都安装了相同的操作系统(Windows XP Service Pack 3).但是我将从互联网上获取VB-6.0代码并运行此代码,而不从其他节点m/c中读取远程注册表项的值.
我尝试&试试这个问题,但是解决不了.
我该如何解决这个问题??
请给我Plz向我提供vb-6.0/vb.net编码...

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

以下vb6.0代码如下:

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 :

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

推荐答案

您是否听说过WMI(Windows管理规范)?这是在另一台计算机上访问注册表的最简单方法之一.实际上,几乎所有资源都位于远程计算机上.

您也可以使用RegistryKey.OpenRemoteBaseKey方法.

http://msdn.microsoft.com/en-us/library/microsoft. win32.registrykey.openremotebasekey.aspx [ ^ ]
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[^]


这篇关于从远程节点读取注册表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆