Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

windows registry access help

franbmfranbm Posts: 2Member
i have this code to list registry key values and subkeys
[code]#include
#include
#include

#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
&cchClassName, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&cbMaxSubKey, // longest subkey size
&cchMaxClass, // longest class string
&cValues, // number of values for this key
&cchMaxValue, // longest value name
&cbMaxValueData, // longest value data
&cbSecurityDescriptor, // security descriptor
&ftLastWriteTime); // last write time

// Enumerate the subkeys, until RegEnumKeyEx fails.

if (cSubKeys)
{
printf( "
Number of subkeys: %d
", 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
"), i+1, achKey);
}
}
}
// Enumerate the key values.

if (cValues)
{
printf( "
Number of values: %d
", cValues);

for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++)
{

const DWORD maxValueBytes=300;
BYTE valueBytes[maxValueBytes];
DWORD valueSize=maxValueBytes;
DWORD valueType=0;
cchValue = MAX_VALUE_NAME;
achValue[0] = '';
retCode = RegEnumValue(hKey, i,
achValue,
&cchValue,
NULL,
&valueType,
valueBytes,
&valueSize);

if (retCode == ERROR_SUCCESS )
{
_tprintf(TEXT("(%d) %s (%d - %d bytes)
"), i+1, achValue,valueType,valueSize);
switch (valueType) {
case REG_BINARY:
_tprintf(TEXT(" The value is binary (0x%X, 0x%X, 0x%X ...)
"),valueBytes[0],valueBytes[1],valueBytes[2]);
break;
case REG_DWORD:
//case REG_DWORD_LITTLE_ENDIAN:
_tprintf(TEXT(" The value is a DWORD (%d)
"),*(DWORD *)valueBytes);
break;
case REG_DWORD_BIG_ENDIAN:
_tprintf(TEXT(" The value is a DWORD (big endian) (%d)
"),(valueBytes[0]<<24)|(valueBytes[1]<<16)|(valueBytes[2]<<8)|valueBytes[3]);
break;
case REG_EXPAND_SZ:
case REG_SZ:
_tprintf(TEXT(" The value is a string
"));
break;
case REG_LINK:
_tprintf(TEXT(" The value is a link
"));
break;
case REG_MULTI_SZ:
_tprintf(TEXT(" The value is a multi-string
"));
break;
case REG_NONE:
_tprintf(TEXT(" There is no spoon... sorry, value
"));
break;
case REG_RESOURCE_LIST:
_tprintf(TEXT(" The value is a resource list
"));
break;
default:
_tprintf(TEXT(" Unknown value type
"));
break;
}
}
else
{
_tprintf(TEXT("error reading value %d - %d
"),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,
&hTestKey) == ERROR_SUCCESS
)
{
QueryKey(hTestKey);
}

RegCloseKey(hTestKey);
system("pause");
}[/code]
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
thanks a lot
Sign In or Register to comment.