<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Registry rekursiv durchsuchen]]></title><description><![CDATA[<p>Guten Tag die Herren.</p>
<p>Ich versuche gerade ein Programm zu schreiben, dass die Registry rekursiv durchsucht. Das tut es soweit auch. Allergings hab ich irgendwo noch ein Fehler drin, und ich komm einfach ums Verrecken nicht drauf wo der Fehler liegt. Ich such jetzt schon seit Tagen danach. Ich hoffe deshalb ihr habt ein geschulteres Auge dafür.</p>
<p>Also hier mal ein wenig code:</p>
<pre><code>bool CKlasse::StartSearching()
{

	strncpy(szSearchPath, &quot;HKEY_LOCAL_MACHINE&quot;, sizeof(szSearchPath)-1);

	HKEY hTestKey;
	if( RegOpenKeyEx( ROOTKEY, TEXT(&quot;&quot;), 0, KEY_READ, &amp;hTestKey) == ERROR_SUCCESS )
	{
			SearchKeys(hTestKey);
			RegCloseKey(hTestKey);
	}
        return true;
}

void CKlasse::SearchKeys(HKEY hKey)
{
	TCHAR    achKey[MAX_KEY_LENGTH];		// buffer for subkey name
    DWORD    cbName;						// size of name string 
    TCHAR    achClass[MAX_PATH] = _T(&quot;&quot;);	// 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 

	TCHAR	szErr[128];						// TODO: wird das noch 

benötigt?

	int ret = 0;

	BYTE  lpData[MAX_VALUE_NAME];
	DWORD lpcbData, valType;

    DWORD i = 0, 
		 ii = 0, 
		 retCode;

	TCHAR achValue[MAX_VALUE_NAME];    
    DWORD cchValue = MAX_VALUE_NAME; 

	HKEY hTestKey;

    // Get the class name and the value count. 
    retCode = RegQueryInfoKey(
        hKey,                    // key handle 
        achClass,                // buffer for class name 
        &amp;cchClassName,           // size of class string 
        NULL,                    // reserved 
        &amp;cSubKeys,               // number of subkeys 
        &amp;cbMaxSubKey,            // longest subkey size 
        &amp;cchMaxClass,            // longest class string 
        &amp;cValues,                // number of values for this key 
        &amp;cchMaxValue,            // longest value name 
        &amp;cbMaxValueData,         // longest value data 
        &amp;cbSecurityDescriptor,   // security descriptor 
        &amp;ftLastWriteTime);       // last write time 

	// If there are values in the key, read them
	if(cValues)
	{
        cchValue = MAX_VALUE_NAME; 
		lpcbData = MAX_VALUE_NAME;

        achValue[0] = '\0'; 
		lpData[0] = '\0';
		valType = 0;

		for (i=0; i&lt;cValues; i++)
		{
            RegEnumValue(	hKey, i, 
							achValue, 
							&amp;cchValue, 
							NULL, 
							&amp;valType,		// typ of value (1 = 

char)
							lpData,
							&amp;lpcbData);

//			TRACE(&quot;(%d) %s - %s\n&quot;, b, path, achValue);
		}
		// b--;
	}

    // Enumerate the subkeys, until RegEnumKeyEx fails.
    if (cSubKeys)
	{	
        for (i=0; i&lt;cSubKeys; i++)
		{ 
            cbName = MAX_KEY_LENGTH;
            retCode = RegEnumKeyEx(hKey, i,
					 achKey, 
                     &amp;cbName, 
                     NULL, 
                     NULL, 
                     NULL, 
                     &amp;ftLastWriteTime); 

            if ( retCode == ERROR_SUCCESS )
			{
				path += &quot;\\&quot;;
				path += achKey;

				ret = RegOpenKeyEx( hKey, achKey, 0, KEY_READ, &amp;hTestKey );
				if( ret == ERROR_SUCCESS )
				{
					SearchKeys( hTestKey );
					RegCloseKey( hTestKey );
				}
				else
				{
					FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | 

FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, ret, 0, szErr, sizeof(szErr), NULL); 
					strncat(szErr, achKey, sizeof(szErr)-1);
					strncat(szErr, &quot;\n\n&quot;, sizeof(szErr)-1);
					TRACE(szErr);
					path = &quot;&quot;;
					RegCloseKey( hTestKey );
				}
			}
        }
    }

	if(cSubKeys &lt;= 0)
	{

		int tmpPathLength = tmpPath.GetLength();
		int tmpB = b;

		for(int ff = tmpPathLength; ff &gt;= 0; ff--)
		{
			if(tmpPath.GetAt(ff) == '\\')
			{
				if(tmpB &gt; 0)
				{
					tmpPath.Delete(ff, tmpPathLength);
				}
				tmpB--;
			}
		}

		tmpPath += path;

		//TODO: search option must be placed here
		//      (code example see below..)
		CString s(tmpPath);
		CString ss(&quot;test&quot;);			// search string

		s.MakeLower();
		ss.MakeLower();

		if(s.Find(ss) &gt;= 0)
		{
			TRACE(&quot;FOUND: %s\n&quot;, tmpPath);

			strncpy(szSearchPath, &quot;HKEY_LOCAL_MACHINE&quot;, sizeof(szSearchPath)-1);
			strncat(szSearchPath, tmpPath, sizeof(szSearchPath)-1);

			REGKEY *newKey = NULL;
			newKey = addElement(&amp;startPtr);

			strncpy(newKey-&gt;szPath, szSearchPath, strlen(szSearchPath));
			newKey-&gt;szType = 'K';

			memset(szSearchPath, 0, sizeof(szSearchPath));
		}
		path.Delete(0, path.GetLength());

		b = 0;
	}
	b++;
}
</code></pre>
<p>Das Problem ist, dass wenn ich z.B. eine solche Ausgabe bekomme:</p>
<blockquote>
<p>HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\test<br />
HKEY_LOCAL_MACHINE\test<br />
HKEY_LOCAL_MACHINE\CurrentControlSet\test</p>
</blockquote>
<p>wobei der erste Key noch richtig ist. Also der Pfad stimmt. Bei den nächsten 2 fehlen dann aber schon Unterordner.<br />
zb: &quot;KEY_LOCAL_MACHINE\CurrentControlSet\test&quot; müsste &quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\test&quot; heißen.</p>
<p>Vielen dank schonmal.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/175701/registry-rekursiv-durchsuchen</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 15:28:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/175701.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 13 Mar 2007 11:55:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Registry rekursiv durchsuchen on Tue, 13 Mar 2007 11:55:49 GMT]]></title><description><![CDATA[<p>Guten Tag die Herren.</p>
<p>Ich versuche gerade ein Programm zu schreiben, dass die Registry rekursiv durchsucht. Das tut es soweit auch. Allergings hab ich irgendwo noch ein Fehler drin, und ich komm einfach ums Verrecken nicht drauf wo der Fehler liegt. Ich such jetzt schon seit Tagen danach. Ich hoffe deshalb ihr habt ein geschulteres Auge dafür.</p>
<p>Also hier mal ein wenig code:</p>
<pre><code>bool CKlasse::StartSearching()
{

	strncpy(szSearchPath, &quot;HKEY_LOCAL_MACHINE&quot;, sizeof(szSearchPath)-1);

	HKEY hTestKey;
	if( RegOpenKeyEx( ROOTKEY, TEXT(&quot;&quot;), 0, KEY_READ, &amp;hTestKey) == ERROR_SUCCESS )
	{
			SearchKeys(hTestKey);
			RegCloseKey(hTestKey);
	}
        return true;
}

void CKlasse::SearchKeys(HKEY hKey)
{
	TCHAR    achKey[MAX_KEY_LENGTH];		// buffer for subkey name
    DWORD    cbName;						// size of name string 
    TCHAR    achClass[MAX_PATH] = _T(&quot;&quot;);	// 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 

	TCHAR	szErr[128];						// TODO: wird das noch 

benötigt?

	int ret = 0;

	BYTE  lpData[MAX_VALUE_NAME];
	DWORD lpcbData, valType;

    DWORD i = 0, 
		 ii = 0, 
		 retCode;

	TCHAR achValue[MAX_VALUE_NAME];    
    DWORD cchValue = MAX_VALUE_NAME; 

	HKEY hTestKey;

    // Get the class name and the value count. 
    retCode = RegQueryInfoKey(
        hKey,                    // key handle 
        achClass,                // buffer for class name 
        &amp;cchClassName,           // size of class string 
        NULL,                    // reserved 
        &amp;cSubKeys,               // number of subkeys 
        &amp;cbMaxSubKey,            // longest subkey size 
        &amp;cchMaxClass,            // longest class string 
        &amp;cValues,                // number of values for this key 
        &amp;cchMaxValue,            // longest value name 
        &amp;cbMaxValueData,         // longest value data 
        &amp;cbSecurityDescriptor,   // security descriptor 
        &amp;ftLastWriteTime);       // last write time 

	// If there are values in the key, read them
	if(cValues)
	{
        cchValue = MAX_VALUE_NAME; 
		lpcbData = MAX_VALUE_NAME;

        achValue[0] = '\0'; 
		lpData[0] = '\0';
		valType = 0;

		for (i=0; i&lt;cValues; i++)
		{
            RegEnumValue(	hKey, i, 
							achValue, 
							&amp;cchValue, 
							NULL, 
							&amp;valType,		// typ of value (1 = 

char)
							lpData,
							&amp;lpcbData);

//			TRACE(&quot;(%d) %s - %s\n&quot;, b, path, achValue);
		}
		// b--;
	}

    // Enumerate the subkeys, until RegEnumKeyEx fails.
    if (cSubKeys)
	{	
        for (i=0; i&lt;cSubKeys; i++)
		{ 
            cbName = MAX_KEY_LENGTH;
            retCode = RegEnumKeyEx(hKey, i,
					 achKey, 
                     &amp;cbName, 
                     NULL, 
                     NULL, 
                     NULL, 
                     &amp;ftLastWriteTime); 

            if ( retCode == ERROR_SUCCESS )
			{
				path += &quot;\\&quot;;
				path += achKey;

				ret = RegOpenKeyEx( hKey, achKey, 0, KEY_READ, &amp;hTestKey );
				if( ret == ERROR_SUCCESS )
				{
					SearchKeys( hTestKey );
					RegCloseKey( hTestKey );
				}
				else
				{
					FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | 

FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, ret, 0, szErr, sizeof(szErr), NULL); 
					strncat(szErr, achKey, sizeof(szErr)-1);
					strncat(szErr, &quot;\n\n&quot;, sizeof(szErr)-1);
					TRACE(szErr);
					path = &quot;&quot;;
					RegCloseKey( hTestKey );
				}
			}
        }
    }

	if(cSubKeys &lt;= 0)
	{

		int tmpPathLength = tmpPath.GetLength();
		int tmpB = b;

		for(int ff = tmpPathLength; ff &gt;= 0; ff--)
		{
			if(tmpPath.GetAt(ff) == '\\')
			{
				if(tmpB &gt; 0)
				{
					tmpPath.Delete(ff, tmpPathLength);
				}
				tmpB--;
			}
		}

		tmpPath += path;

		//TODO: search option must be placed here
		//      (code example see below..)
		CString s(tmpPath);
		CString ss(&quot;test&quot;);			// search string

		s.MakeLower();
		ss.MakeLower();

		if(s.Find(ss) &gt;= 0)
		{
			TRACE(&quot;FOUND: %s\n&quot;, tmpPath);

			strncpy(szSearchPath, &quot;HKEY_LOCAL_MACHINE&quot;, sizeof(szSearchPath)-1);
			strncat(szSearchPath, tmpPath, sizeof(szSearchPath)-1);

			REGKEY *newKey = NULL;
			newKey = addElement(&amp;startPtr);

			strncpy(newKey-&gt;szPath, szSearchPath, strlen(szSearchPath));
			newKey-&gt;szType = 'K';

			memset(szSearchPath, 0, sizeof(szSearchPath));
		}
		path.Delete(0, path.GetLength());

		b = 0;
	}
	b++;
}
</code></pre>
<p>Das Problem ist, dass wenn ich z.B. eine solche Ausgabe bekomme:</p>
<blockquote>
<p>HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\test<br />
HKEY_LOCAL_MACHINE\test<br />
HKEY_LOCAL_MACHINE\CurrentControlSet\test</p>
</blockquote>
<p>wobei der erste Key noch richtig ist. Also der Pfad stimmt. Bei den nächsten 2 fehlen dann aber schon Unterordner.<br />
zb: &quot;KEY_LOCAL_MACHINE\CurrentControlSet\test&quot; müsste &quot;HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\test&quot; heißen.</p>
<p>Vielen dank schonmal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1244604</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1244604</guid><dc:creator><![CDATA[Guest666]]></dc:creator><pubDate>Tue, 13 Mar 2007 11:55:49 GMT</pubDate></item><item><title><![CDATA[Reply to Registry rekursiv durchsuchen on Tue, 13 Mar 2007 12:24:12 GMT]]></title><description><![CDATA[<p>Nur so als Hinweis:</p>
<p>RegEnumKeyEx should return all keys, shouldn´t it?<br />
<a href="http://blog.kalmbachnet.de/?postid=41" rel="nofollow">http://blog.kalmbachnet.de/?postid=41</a></p>
<p>The registry becomes more and more complex...<br />
<a href="http://blog.kalmbachnet.de/?postid=99" rel="nofollow">http://blog.kalmbachnet.de/?postid=99</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1244626</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1244626</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Tue, 13 Mar 2007 12:24:12 GMT</pubDate></item><item><title><![CDATA[Reply to Registry rekursiv durchsuchen on Tue, 13 Mar 2007 13:05:27 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>dass die Registry inzwischen ein rießen Ramschladen ist, was nicht mal mehr MS richtig durchschaut war mir schon klar. Allerdings kann Registry Reflection bei mir nicht die Ursache sein, da ich ja eine 32Bit Version von XP habe.</p>
<p>Müsste irgendein Codefehler sein. Leider ist das alles sehr komplex wegen der Rekursion. Deshalb hab ich auch Debuggingprobleme.</p>
<p>Aber schonmal vielen Dank!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1244660</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1244660</guid><dc:creator><![CDATA[Guest666]]></dc:creator><pubDate>Tue, 13 Mar 2007 13:05:27 GMT</pubDate></item></channel></rss>