vb读取 注册表固定 键 很简单
但 HKEY_USERS 下的 
S-1-5-21-2820545974-3949396129-26281047-500 键在每一台机子下都不同
前面的 S-1-5-21  和 后面的 -500  是相同的 中间-2820545974-3949396129-26281047 都不同 
像这一类 变化的键 我如何读取它 下面的键呢?

解决方案 »

  1.   

    fangyc 说的还很 模糊 我是菜鸟
    有哪位 大侠 能指点下啊急需 解决这个问题 否则写出来的东西 只能在一台机子上用
    换一台机子就不管用了
    S-1-5-21-********-500     中间 **** 都是机子根据时间 安装信息 随即生成的
    我怎么才能读取它下面的 键 和键值呢
      

  2.   

    你的意思是说你要调用到API来读取有关Registry的值么?Public Const HKEY_CLASSES_ROOT = &H80000000
    Public Const HKEY_CURRENT_USER = &H80000001
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Const HKEY_USERS = &H80000003
    Public Const HKEY_PERFORMANCE_DATA = &H80000004
    Public Const ERROR_SUCCESS = 0&' Registry API prototypesDeclare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
    Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
    Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
    Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
    Public Const REG_SZ = 1                         ' Unicode nul terminated string
    Public Const REG_DWORD = 4                      ' 32-bit numberPublic Sub savekey(hKey As Long, strPath As String)
    Dim keyhand&
    r = RegCreateKey(hKey, strPath, keyhand&)
    r = RegCloseKey(keyhand&)
    End SubPublic Function getstring(hKey As Long, strPath As String, strValue As String)Dim keyhand As Long
    Dim datatype As Long
    Dim lResult As Long
    Dim strBuf As String
    Dim lDataBufSize As Long
    Dim intZeroPos As Integer
    r = RegOpenKey(hKey, strPath, keyhand)
    lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
    If lValueType = REG_SZ Then
        strBuf = String(lDataBufSize, " ")
        lResult = RegQueryValueEx(keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
        If lResult = ERROR_SUCCESS Then
            intZeroPos = InStr(strBuf, Chr$(0))
            If intZeroPos > 0 Then
                getstring = Left$(strBuf, intZeroPos - 1)
            Else
                getstring = strBuf
            End If
        End If
    End If
    End Function
    Public Sub savestring(hKey As Long, strPath As String, strValue As String, strdata As String)
    Dim keyhand As Long
    Dim r As Long
    r = RegCreateKey(hKey, strPath, keyhand)
    r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
    r = RegCloseKey(keyhand)
    End Sub
    Function getdword(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String) As Long
    Dim lResult As Long
    Dim lValueType As Long
    Dim lBuf As Long
    Dim lDataBufSize As Long
    Dim r As Long
    Dim keyhand As Longr = RegOpenKey(hKey, strPath, keyhand) ' Get length/data type
    lDataBufSize = 4
        
    lResult = RegQueryValueEx(keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)If lResult = ERROR_SUCCESS Then
        If lValueType = REG_DWORD Then
            getdword = lBuf
        End If
    'Else
    '    Call errlog("GetDWORD-" & strPath, False)
    End Ifr = RegCloseKey(keyhand)
        
    End FunctionFunction SaveDword(ByVal hKey As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
        Dim lResult As Long
        Dim keyhand As Long
        Dim r As Long
        r = RegCreateKey(hKey, strPath, keyhand)
        lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4)
        'If lResult <> error_success Then Call errlog("SetDWORD", False)
        r = RegCloseKey(keyhand)
    End FunctionPublic Function DeleteKey(ByVal hKey As Long, ByVal strKey As String)
    Dim r As Long
    r = RegDeleteKey(hKey, strKey)
    End FunctionPublic Function DeleteValue(ByVal hKey As Long, ByVal strPath As String, ByVal strValue As String)
    Dim keyhand As Long
    r = RegOpenKey(hKey, strPath, keyhand)
    r = RegDeleteValue(keyhand, strValue)
    r = RegCloseKey(keyhand)
    End Function使用方法:Call savestring(HKEY_LOCAL_MACHINE, "Software\myapp", "myname", "myval")myval = getstring(HKEY_LOCAL_MACHINE, "Software\myapp", "myname")