John_Reese
May 31st, 1999, 06:41 AM
Hello. I need some code that will allow me to access a known path through the registry and read an unknown value name and value, of which I know the index. In other words, I need to be able to read the default value in a folder to check for present software...The default is not always called "default", in German it's "Standard", in French, ??. Can anyone help me with this?
G. Garman
June 1st, 1999, 02:18 PM
Here is some sample code which uses RegQueryInfoKey
and loops through the sub keys. You could look via a case statement for whatever values you want and do as you see fit.
void CCFISetupDlg::QueryKey(HANDLE hKey)
{
CHAR achKey[MAX_PATH];
CHAR achClass[MAX_PATH] = ""; // buffer for class name
DWORD cchClassName = MAX_PATH; // length of class string
DWORD cSubKeys; // 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;
DWORD retCode;
DWORD cchValue = _MAX_FNAME;
// Get the class name and the value count.
RegQueryInfoKey((struct HKEY__ *)hKey, // key handle
achClass, // buffer for class name
&cchClassName, // length 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 child keys, looping until RegEnumKey fails. Then
// get the name of each child key and copy it into the list box.
for (
i = 0, retCode = ERROR_SUCCESS;
retCode == ERROR_SUCCESS;
i++
)
{
retCode = RegEnumKey((struct HKEY__ *)hKey, i, achKey, MAX_PATH);
if (retCode == (DWORD)ERROR_SUCCESS)
{
//valid key
struct HKEY__ * hNextKey;
int RegOpenRet;
//search for our value
if (strcmp(achKey,"TEST") == 0 )
{
switch (1)
{
case 1:
RegOpenRet = RegOpenKeyEx( (struct HKEY__ *)hKey,"Microsoft",0,KEY_READ,&hNextKey);
if (RegOpenRet != (DWORD)ERROR_SUCCESS)
printf("help");
QueryKey(hNextKey);
}
}
}
}
}
John_Reese
June 2nd, 1999, 01:40 AM
Hey, thanks for the response...We actually figured out yesterday that if you pass a NULL as the value name, it returns the default value, which is what we need...I appreciate your help though...