0
HKEY hkey;
	DWORD nSubKeys = 0;
	TCHAR name[MAX_PATH];
	DWORD size = sizeof(name);
	FILETIME filetime;

	if(RegOpenKeyEx(HKEY_CURRENT_USER , "Software" , 0 , KEY_QUERY_VALUE  , &hkey) == ERROR_SUCCESS)
	{
		if(RegQueryInfoKey(hkey , 0 , 0 , 0 , &nSubKeys , 0 , 0 , 0 , 0 , 0 ,  0 , &filetime) == ERROR_SUCCESS)
		{
			if(nSubKeys)
			{
				cout << "Number of subkeys: " << nSubKeys << endl;
				for(DWORD i = 0; i < nSubKeys; i++)
				{
					if(RegEnumKeyEx(hkey , i , name , &size , 0 , 0 , 0 , &filetime) == ERROR_SUCCESS)
					{
						cout << i << ":" << name << endl;
					}
				}
			}
		}
	}

It prints that are 68 keys,but it doesnt print every key,one by one ,why is that ?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by vbx_wx
0

You need to use the KEY_ENUMERATE_SUB_KEYS flag when opening the key ..

// ..
if(RegOpenKeyEx(
  HKEY_CURRENT_USER , "Software" , 0 ,
  KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE,
  &hkey) == ERROR_SUCCESS) {
// ..

Note that a successful RegEnumKeyEx() call will change the value of the size parameter to be the length of the subkey. So, you need to ensure that you pass in the real size of the name buffer upon each call to RegEnumKeyEx() .

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.