<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'windows registry access help' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'windows registry access help' posted on the 'C and C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 20:41:24 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 20:41:24 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>windows registry access help</title>
      <link>http://www.programmersheaven.com/mb/CandCPP/428365/428365/windows-registry-access-help/</link>
      <description>i have this code to list registry key values and subkeys&lt;br /&gt;
&lt;pre class="sourcecode"&gt;#include &amp;lt;windows.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;tchar.h&amp;gt;

#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,                    // key handle 
        achClass,                // buffer for class name 
        &amp;amp;cchClassName,           // size of class string 
        NULL,                    // reserved 
        &amp;amp;cSubKeys,               // number of subkeys 
        &amp;amp;cbMaxSubKey,            // longest subkey size 
        &amp;amp;cchMaxClass,            // longest class string 
        &amp;amp;cValues,                // number of values for this key 
        &amp;amp;cchMaxValue,            // longest value name 
        &amp;amp;cbMaxValueData,         // longest value data 
        &amp;amp;cbSecurityDescriptor,   // security descriptor 
        &amp;amp;ftLastWriteTime);       // last write time 
 
    // Enumerate the subkeys, until RegEnumKeyEx fails.
    
    if (cSubKeys)
    {
        printf( "\nNumber of subkeys: %d\n", cSubKeys);

        for (i=0; i&amp;lt;cSubKeys; i++) 
        { 
            cbName = MAX_KEY_LENGTH;
            retCode = RegEnumKeyEx(hKey, i,
                     achKey, 
                     &amp;amp;cbName, 
                     NULL, 
                     NULL, 
                     NULL, 
                     &amp;amp;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&amp;lt;cValues; i++) 
        { 
       
	const DWORD maxValueBytes=300;
        BYTE valueBytes[maxValueBytes];
        DWORD valueSize=maxValueBytes;
        DWORD valueType=0;
        cchValue = MAX_VALUE_NAME;  
        achValue[0] = '\0';  
        retCode = RegEnumValue(hKey, i,  
            achValue,  
            &amp;amp;cchValue,  
            NULL,  
            &amp;amp;valueType, 
            valueBytes, 
            &amp;amp;valueSize); 

        if (retCode == ERROR_SUCCESS )  
        {  
            _tprintf(TEXT("(%d) %s (%d - %d bytes)\n"), i+1, achValue,valueType,valueSize);  
            switch (valueType) {
                case REG_BINARY:
                    _tprintf(TEXT("   The value is binary (0x%X, 0x%X, 0x%X ...)\n"),valueBytes[0],valueBytes[1],valueBytes[2]
);
                    break;
                case REG_DWORD:
                //case REG_DWORD_LITTLE_ENDIAN:
                    _tprintf(TEXT("   The value is a DWORD (%d)\n"),*(DWORD *)valueBytes);
                    break;
                case REG_DWORD_BIG_ENDIAN:
                    _tprintf(TEXT("   The value is a DWORD (big endian) (%d)\n"),(valueBytes[0]&amp;lt;&amp;lt;24)|(valueBytes[1]&amp;lt;&amp;lt;16)|(
valueBytes[2]&amp;lt;&amp;lt;8)|valueBytes[3]);
                    break;
                case REG_EXPAND_SZ:
                case REG_SZ:
                    _tprintf(TEXT("   The value is a string\n"));
                  break;
                case REG_LINK:
                    _tprintf(TEXT("   The value is a link\n"));
                  break;
                case REG_MULTI_SZ:
                    _tprintf(TEXT("   The value is a multi-string\n"));
                  break;
                case REG_NONE:
                    _tprintf(TEXT("   There is no spoon... sorry, value\n"));
                  break;
                case REG_RESOURCE_LIST:
                    _tprintf(TEXT("   The value is a resource list\n"));
                  break;
                default:
                    _tprintf(TEXT("   Unknown value type\n"));
                  break;
            }
        }
        else
        {
            _tprintf(TEXT("error reading value %d - %d\n"),i+1,retCode);
        }

        }
    }
}

void __cdecl _tmain(void)
{
   HKEY hTestKey;

 //  if( RegOpenKeyEx( HKEY_CURRENT_USER,
  //      TEXT("SOFTWARE\\Microsoft"),
     if( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
        TEXT("SYSTEM\\Setup"),
        0,
        KEY_READ,
        &amp;amp;hTestKey) == ERROR_SUCCESS
      )
   {
      QueryKey(hTestKey);
   }
   
   RegCloseKey(hTestKey);
   system("pause");
}&lt;/pre&gt;&lt;br /&gt;
how can i modify the function void QueryKey(HKEY hKey) to return registry key values and subvalues and list/print them in void __cdecl _tmain(void) function&lt;br /&gt;
thanks a lot&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/CandCPP/428365/428365/windows-registry-access-help/</guid>
      <pubDate>Thu, 19 Apr 2012 17:18:55 -0700</pubDate>
      <category>C and C++</category>
    </item>
  </channel>
</rss>