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 ?

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() .

You are right,it works now,thanx a lot .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.