Hi All,
I am trying to enumerate the subkeys of a given registry
key, but unfortunately I still have no luck.

Here is the code:

#define DIM_MANAGEMENT_PATH 512
...

int i;
unsigned long dim;
HRESULT ret;
HKEY key;
wchar_t child[DIM_MANAGEMENT_PATH];
wchar_t fullName[DIM_MANAGEMENT_PATH];

RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
//fullContext,
TEXT("Software"),
0,
KEY_ENUMERATE_SUB_KEYS,
&key
);

if (key == 0) {
// some error handling

}

for (i=0; i<*size; ++i) {
dim = DIM_MANAGEMENT_PATH;
ret = RegEnumKeyEx(key, i, child, &dim, NULL, NULL,
NULL, NULL);
if (ret != ERROR_SUCCESS) {
LOG.debug(TEXT("Not NULL"));
if (ret == ERROR_NO_MORE_ITEMS) {
break;
} else {
// some error handling


goto finally;
}
}

LOG.debug(child);

children[i] = new PPCManagementNode(fullName, child);
}

*size = i;


finally:

if (key != 0) {
RegCloseKey(key);
}

Re: Enumerating registry subkeys by Rob

Rob
Thu Dec 11 14:34:54 CST 2003

What errors are you getting? Also, better to check the return value of
RegOpenKeyEx than to expect key to be NULL on an error, which is not
guaranteed by the docs....

--
Rob Elmer
Mobile Devices Product Group
This posting is provided "AS IS" with no warranties, and confers no rights.


"Stefano" <anonymous@discussions.microsoft.com> wrote in message
news:0b3101c3bfd6$09d44a40$a101280a@phx.gbl...
> Hi All,
> I am trying to enumerate the subkeys of a given registry
> key, but unfortunately I still have no luck.
>
> Here is the code:
>
> #define DIM_MANAGEMENT_PATH 512
> ...
>
> int i;
> unsigned long dim;
> HRESULT ret;
> HKEY key;
> wchar_t child[DIM_MANAGEMENT_PATH];
> wchar_t fullName[DIM_MANAGEMENT_PATH];
>
> RegOpenKeyEx(
> HKEY_LOCAL_MACHINE,
> //fullContext,
> TEXT("Software"),
> 0,
> KEY_ENUMERATE_SUB_KEYS,
> &key
> );
>
> if (key == 0) {
> // some error handling
>
> }
>
> for (i=0; i<*size; ++i) {
> dim = DIM_MANAGEMENT_PATH;
> ret = RegEnumKeyEx(key, i, child, &dim, NULL, NULL,
> NULL, NULL);
> if (ret != ERROR_SUCCESS) {
> LOG.debug(TEXT("Not NULL"));
> if (ret == ERROR_NO_MORE_ITEMS) {
> break;
> } else {
> // some error handling
>
>
> goto finally;
> }
> }
>
> LOG.debug(child);
>
> children[i] = new PPCManagementNode(fullName, child);
> }
>
> *size = i;
>
>
> finally:
>
> if (key != 0) {
> RegCloseKey(key);
> }