2 Replies - 1776 Views - Last Post: 23 April 2016 - 08:28 PM Rate Topic: -----

#1 Yanni yanni   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-April 16

Enumerate Registry key Value and Data !

Posted 23 April 2016 - 12:48 AM

I am still a beginner in C , I found a useful code in C whcih helped me getting a Key Values but i am Trying to print ("SOFTWARE\Microsoft\Windows NT\CurrentVersion") with all it's values and data , but i can only get the Values without the Data , i would like to get both Values and it's data like (ProductName :Windows 7 , SystemRoot : C:\Windows , etc ... ) , if someone can help me with this code i would be so grateful , i used "RegQueryValueEx" but it only gives me a specific data for a single value .
Thanks.


#include <windows.h>
#include <stdio.h>
#include <tchar.h>

#define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383
void QueryKey(HKEY hKey)
{
    TCHAR   achKey[MAX_KEY_LENGTH];   // buffer for subkey name
    DWORD   cbName;                // size of name string
    TCHAR   achClass[MAX_PATH] = TEXT("");  // buffer for class name
    DWORD   cchClassName = MAX_PATH;  // size of class string
    DWORD   cSubKeys=0;            // 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, retCode;
    TCHAR  achValue[MAX_VALUE_NAME];
    DWORD cchValue = MAX_VALUE_NAME;
    // Get the class name and the value count.
    retCode = RegQueryInfoKey(hKey,achClass,&cchClassName,NULL,&cSubKeys,&cbMaxSubKey,&cchMaxClass,&cValues,&cchMaxValue,&cbMaxValueData,&cbSecurityDescriptor,&ftLastWriteTime);
    // Enumerate the subkeys, until RegEnumKeyEx fails.
    if (cSubKeys)
    {
        printf( "\nNumber of subkeys: %d\n", cSubKeys);
        for (i=0; i<cSubKeys; i++)
        {
            cbName = MAX_KEY_LENGTH;retCode = RegEnumKeyEx(hKey, i,achKey,&cbName,NULL,NULL,NULL,&ftLastWriteTime);
            if (retCode == ERROR_SUCCESS)
            {
                _tprintf(TEXT("(%d) %s\n"), i+1, achKey);
            }
        }
    }
    // Enumerate the key values.
    if (cValues)
    {
        printf( "\nNumber of values: %d\n", cValues);
        for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++)
        {
            cchValue = MAX_VALUE_NAME;
            achValue[0] = '\0';
            retCode = RegEnumValue(hKey, i, achValue, &cchValue, NULL,  NULL, NULL, NULL);
            if (retCode == ERROR_SUCCESS )
            {
                _tprintf(TEXT("(%d) %s\n"), i+1, achValue);
            }
        }
    }
}

void _tmain(void)
{
   HKEY hTestKey;
   if( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
        TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),0, KEY_READ, &hTestKey) == ERROR_SUCCESS
      )

   {
      QueryKey(hTestKey);

   }
   RegCloseKey(hTestKey);
}



Is This A Good Question/Topic? 0
  • +

Replies To: Enumerate Registry key Value and Data !

#2 Yanni yanni   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-April 16

Re: Enumerate Registry key Value and Data !

Posted 23 April 2016 - 07:22 AM

Anyone can help me , i really need this
:(
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,430
  • Joined: 05-May 12

Re: Enumerate Registry key Value and Data !

Posted 23 April 2016 - 08:27 PM

View PostYanni yanni, on 23 April 2016 - 03:48 AM, said:

i used "RegQueryValueEx" but it only gives me a specific data for a single value .

I don't see any call to ReqQueryValueEx() in the code you presented. It's kind of hard to help you if you don't show us what you say you need help with.

As for the current code you did post where your call RegEnumValue(), you are passing NULLs and zeros for the out parameters that will give you the values. Why are you surprised that you aren't getting the values when you aren't telling the computer where to store the data that you want.

View PostYanni yanni, on 23 April 2016 - 03:48 AM, said:

I am still a beginner in C


View PostYanni yanni, on 23 April 2016 - 10:22 AM, said:

Anyone can help me , i really need this
:(/>


If you are a beginner in C, you really don't need this. What you need is to first become proficient in C programming before you get involved in any systems programming. In Windows programming, there are a lot of assumptions made by the documentation that the reader is sufficiently well versed in C. (Older Windows documentation from Windows 3.x assumed that you were well versed in Pascal as well as C.)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1