急救!在线等待,如何列举注册表的所有的项和值!
我需要列举注册表所有的项和值,并获得项和值的最近修改时间,
该怎么做啊???最好有简单的例子程序!

解决方案 »

  1.   

    The following example demonstrates the use of the RegQueryInfoKey, RegEnumKeyEx, and RegEnumValue functions. The hKey parameter passed to each function is a handle to an open key. This key must be opened before the function call and closed afterward. 
    // QueryKey - Enumerates the subkeys of key, and the associated 
    //    values, then copies the information about the keys and values 
    //    into a pair of edit controls and list boxes. 
    // hDlg - Dialog box that contains the edit controls and list boxes.
    // hKey - Key whose subkeys and values are to be enumerated.
     
    void QueryKey(HWND hDlg, HANDLE hKey) 

        CHAR     achKey[MAX_PATH]; 
        CHAR     achClass[MAX_PATH] = "";  // buffer for class name 
        DWORD    cchClassName = MAX_PATH;  // size of class string 
        DWORD    cSubKeys;                 // number of subkeys 
        DWORD    cbMaxSubKey;              // longest subkey size 
        DWORD    cchMaxClass;              // longest class string 
        DWORD    cValues;              // number of values for key 
        DWORD    cchMaxValue;          // longest value name 
        DWORD    cbMaxValueData;       // longest value data 
        DWORD    cbSecurityDescriptor; // size of security descriptor 
        FILETIME ftLastWriteTime;      // last write time 
     
        DWORD i, j; 
        DWORD retCode, retValue; 
     
        CHAR  achValue[MAX_VALUE_NAME]; 
        DWORD cchValue = MAX_VALUE_NAME; 
        CHAR  achBuff[80]; 
     
        // Get the class name and the value count. 
        RegQueryInfoKey(hKey,        // key handle 
            achClass,                // buffer for class name 
            &cchClassName,           // size of class string 
            NULL,                    // reserved 
            &cSubKeys,               // number of subkeys 
            &cbMaxSubKey,            // longest subkey size 
            &cchMaxClass,            // longest class string 
            &cValues,                // number of values for this key 
            &cchMaxValue,            // longest value name 
            &cbMaxValueData,         // longest value data 
            &cbSecurityDescriptor,   // security descriptor 
            &ftLastWriteTime);       // last write time 
     
        SetDlgItemText(hDlg, IDE_CLASS, achClass); 
        SetDlgItemInt(hDlg, IDE_CVALUES, cValues, FALSE); 
     
        SendMessage(GetDlgItem(hDlg, IDL_LISTBOX), 
            LB_ADDSTRING, 0, (LONG) ".."); 
     
        // Enumerate the child keys, until RegEnumKeyEx fails. Then 
        // get the name of each child key and copy it into the list box.     SetCursor(LoadCursor(NULL, IDC_WAIT)); 
        for (i = 0, retCode = ERROR_SUCCESS; 
                retCode == ERROR_SUCCESS; i++) 
        { 
            retCode = RegEnumKeyEx(hKey, 
                         i, 
                         achKey, 
                         MAX_PATH, 
                         NULL, 
                         NULL, 
                         NULL, 
                         &ftLastWriteTime); 
            if (retCode == (DWORD)ERROR_SUCCESS) 
            {
                SendMessage(GetDlgItem(hDlg, IDL_LISTBOX), 
                    LB_ADDSTRING, 0, (LONG) achKey); 
            }
        } 
        SetCursor(LoadCursor (NULL, IDC_ARROW)); 
     
        // Enumerate the key values. 
        SetCursor(LoadCursor(NULL, IDC_WAIT)); 
     
        if (cValues) 
        {
            for (j = 0, retValue = ERROR_SUCCESS; 
                    j < cValues; j++) 
            { 
                cchValue = MAX_VALUE_NAME; 
                achValue[0] = '\0'; 
                retValue = RegEnumValue(hKey, j, achValue, 
                    &cchValue, 
                    NULL, 
                    NULL,    // &dwType, 
                    NULL,    // &bData, 
                    NULL);   // &bcData 
     
                if (retValue == (DWORD) ERROR_SUCCESS ) 
                { 
                    achBuff[0] = '\0'; 
     
                    // Add each value to a list box. 
                    if (!lstrlen(achValue)) 
                        lstrcpy(achValue, "<NO NAME>"); 
                    wsprintf(achBuff, "%d) %s ", j, achValue); 
                    SendMessage(GetDlgItem(hDlg,IDL_LISTBOX2), 
                        LB_ADDSTRING, 0, (LONG) achBuff); 
                } 
            }    SetCursor(LoadCursor(NULL, IDC_ARROW)); 
    }
      

  2.   

    好像只能列出下面一层的项和值比如:hKey = HKEY_LOCAL_MACHINE,只列出了:HARDWARE、SAM、SECURITY、SOFTWARE、SYSTEM,我想继续列出HARDWARE、SAM、SECURITY、SOFTWARE、SYSTEM下边的项和值,该怎么做啊??
      

  3.   

    使用RegEnumValue
    注意:
        1.使用RegEnumValue所需的HKEY必须是被用RegOpenKeyEx(,,,KEY_QUERY_VALUE,)打开得到的.
        2.使用RegEnumValue时第二个参数index在第一次调用RegEnumValue时必须是0,否则会返回0x00000103(没有其他可用数据)错误.