2

I have a subkey in my registry with an unknown numbers of values.

I want to get all the data from those values in th specified subkey.

how can I do that ? I don't know the names of the values and the number of values.

I'm programming in C.

thanks!

EFraim
  • 12,811
  • 4
  • 46
  • 62

2 Answers2

3

Here's a code for geting all string values a from given regkey (you must open this key before and close after using this function.

vector<pair<wstring, wstring>> CRegistryManager::getKeyValues(HKEY regKey)
{
    vector<pair<wstring, wstring>> retValues;

    DWORD numOfValues;
    DWORD maxValueNameLen;
    DWORD maxValueDataLen;
    LONG retCode;

    retCode = RegQueryInfoKey(regKey, NULL, NULL,NULL, NULL, NULL, NULL, &numOfValues, &maxValueNameLen, &maxValueDataLen, NULL, NULL);
    if( (retCode == ERROR_SUCCESS) && (numOfValues != 0) )
    {
        TCHAR* valueName = new TCHAR[maxValueNameLen+1];

        TCHAR* valueData = new TCHAR[maxValueDataLen+1];

        for(int i = 0; i < numOfValues; i++)
        {
            DWORD valueNameBuferSize = maxValueNameLen+1;
            DWORD valueDataBufferSize = maxValueDataLen+1;

            retCode = RegEnumValue(regKey, i, valueName, &valueNameBuferSize, NULL,NULL, (LPBYTE)valueData, &valueDataBufferSize);
            if(retCode == ERROR_SUCCESS)
            {
                auto pair = make_pair(wstring(valueName), wstring(valueData));
                retValues.push_back(pair);
            }
        }
        delete[] valueName;
        delete[] valueData;
    }
    return retValues;
}
Mariusz Pawelski
  • 25,983
  • 11
  • 67
  • 80
2

You'll want to use the Win32 API RegEnumValue to enumerate the registry values of a subkey. There is an example on MSDN which is similar to this but for enumerating registry subkeys.

You can also find some helper functions from one of my previous answers here.

Community
  • 1
  • 1
Brian R. Bondy
  • 339,232
  • 124
  • 596
  • 636