Trying to write a function to return an array of installed apps by querying the registry. Nearly there, opening all the enumerated sub keys, but when I try and read the value (reg_sz) it returns error code 2 - not found. Seeing as the value does exist it is driving me a bit mad.
Code is here, if anyone can show me what I am doing wrong I would be most grateful.
Charlie Benger-Stevenson
Hart Hill IT Ltd
Code is here, if anyone can show me what I am doing wrong I would be most grateful.
Code:
int listApps()
{
LPCTSTR lpSubKey[1024];
LPCTSTR lpSubSubKey[1024];
HKEY hkResult=0;
HKEY hkSubKey=0;
char buff[1024]; // temp buffer
char * valueName = "InstallLocation";
DWORD bufflen=sizeof(buff);
DWORD count;
DWORD type;
int index;
int retVal=0;
strcpy(lpSubKey,"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\");
strcpy(lpSubSubKey,"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\");
retVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpSubKey,0,KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,&hkResult);
index=0;
bufflen=sizeof(buff);
while(RegEnumKeyEx(hkResult,
index,
buff,
&bufflen,0,0,0,0)==ERROR_SUCCESS)
{
if(buff[0]!=0)
//m_KeyList.AddString(buff);
printf("%s \n",buff);
strcat(lpSubSubKey,buff);
printf("%s \n",lpSubSubKey);
retVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,lpSubKey,0,KEY_READ,&hkSubKey);
if (retVal==ERROR_SUCCESS)
{
printf("Subkey opened \n");
count=1024;
retVal = RegQueryValueEx(hkSubKey,valueName,0,&type,&buff,&count);
printf("RegQueryValueEx returned %d \n");
if (retVal==ERROR_SUCCESS)
{
printf("InstallLocation = %s \n",buff);
}
RegCloseKey(hkSubKey);
}
strcpy(lpSubSubKey,lpSubKey);
index++;
bufflen=sizeof(buff);
}
Charlie Benger-Stevenson
Hart Hill IT Ltd