The following is a complete executable program in VC:
# Include "stdafx. H"
# Include <stdio. h>
# Include <windows. h>
# Define softpath "software // Microsoft // windows // CurrentVersion // Uninstall"
// Function: Lists All subkey names under a specified key.
Boolmyenumkey (lptstrszkeypath)
{
Hkey;
Long result;
// Open the Registry
Result =: regopenkeyex (HKEY_LOCAL_MACHINE, szkeypath, 0, key_read, & hkey );
If (result! = Error_success)
{
Returnfalse;
}
Tcharszkey [max_path];
Lptstrlpname = szkey;
Dworddwindex = 0; // incremental index used for listing
While (1)
{
Memset (szkey, 0, sizeof (szkey ));
// Lists all the subkeys under a specified key. lpname is used to receive the subkey name.
Result = regenumkey (hkey, dwindex ++, lpname, max_path + 1 );
If (result = error_no_more_items)
{
Break; // All subkeys have been listed
}
If (result! = Error_success)
{
Break;
}
// Display
Printf ("% 03d: keyname = % S/R/N", dwindex, szkey );
}
// Close the registry
: Regclosekey (hkey );
Returntrue;
}
Intmain (intargc, char * argv [])
{
Myenumkey (softpath );
Getchar ();
Return0;
}