2011-12-23 25 views
2

RegEnumValue()は常にエラーコード259をERROR_NO_MORE_ITEMSとして返し、sectionValueはナンセンス値を返します。私はレジストリを手動でチェックし、指定されたキーの下に値があります。C++ RegEnumValue() - 各値の反復処理に失敗しました

たとえば、
キーは、キー値がManualTestCase = 10

キー値は私の推測では、あなたの問題は、あなたがしようとしているlResult = RegEnumKeyEx(hKey, i, sectionName,...

を使用する方法であるであるAutomationTestCase = 50

HKEY hKey;  //registry key handle 
    LONG lResult; //result of registry operations 
    DWORD dwType, dwSize=0; 

    //try to open the key that we are currently pointing at with rootPath 
    lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, rootPath, NULL, KEY_ALL_ACCESS, &hKey); 

    if (lResult == ERROR_SUCCESS) 
    { 
     LPTSTR className = NULL; 
     DWORD classNameSize = MAX_PATH; 
     DWORD subKey = 0; 
     DWORD maxSubKey; 
     DWORD maxClass; 
     DWORD value; 
     DWORD maxValue; 
     DWORD maxValueData; 
     DWORD securityDescriptor; 
     FILETIME ftLastWriteTime; 
     DWORD sectionNameSize; 
     int j; 

     //to get total keys for the specified path 
     lResult = RegQueryInfoKey(hKey, className, &classNameSize, NULL, 
            &subKey, &maxSubKey, &maxClass, &value, &maxValue, 
            &maxValueData, &securityDescriptor, &ftLastWriteTime); 

     if(lResult == ERROR_SUCCESS) 
     { 
      for(int i = 0; i < subKey; i++) 
      {     
       LPTSTR sectionName = new TCHAR[1096]; 
       sectionNameSize = 1096; 
       ftLastWriteTime.dwHighDateTime = 0; 
       ftLastWriteTime.dwLowDateTime = 0; 

       //enumerate all the registry key names for specified path 
       lResult = RegEnumKeyEx(hKey, i, sectionName, 
           &sectionNameSize, NULL, NULL, 
           NULL, &ftLastWriteTime); 

       CString testStr = sectionName; 
       if(lResult == ERROR_SUCCESS) 
       { 
        j = 0; 
        do 
        { 
         LPTSTR sectionValue; 
         DWORD sectionValueSize = 4096; 
         DWORD dwType; 

         //enumerate all the values for specified key 
         lResult = RegEnumValue(hKey, j, sectionName, 
                &sectionNameSize, NULL, &dwType, 
                (LPBYTE)sectionValue, &sectionValueSize); 

         // 
         if(lResult == ERROR_SUCCESS) 
         { 
          //do something to the data 
          bool whatever = true;        
         } 
         else if(lResult == ERROR_MORE_DATA) 
         { 
          // 
          bool yeahSure = true; 
         } 
         j++; 

        }while(lResult != ERROR_NO_MORE_ITEMS); 
       } 

       delete[] sectionName; 
      } 
     } 
    } 

    RegCloseKey(hKey); 

答えて

1

であるMyTestApp

です実際にそのサブキーを開かずにサブキーの値を列挙します。

+0

ありがとうございます。 – Lufia

+0

また、私はKHEY変数hKey1を作成し、RegEnumValue()に渡す必要があります。RegEnumValue(..)を呼び出す前に、RegOpenKeyEx(HKEY_LOCAL_MACHINE、rootPath + "\\" + sectionName、NULL、KEY_ALL_ACCESS、&hKey);を呼び出す前に、 RegOpenKeyEx(,,,,,&hKey1)を参照しています。値を反復処理した後、次のサブキーに到達できないhKey1を閉じる必要があります。 – Lufia

+0

また、値の列挙ループでsectionNameSizeを再初期化するのを忘れました。 –