Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegQueryValueEx driving me mad

Status
Not open for further replies.

chigley

Programmer
Sep 30, 2002
104
0
0
GB
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.

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
 
I am thick. Opening the wrong key, should open lpSubSubKey not lpSubKey.

Can anyone show me how to scoop the data out of the buffer and into a char array?

Ultimately want to return an array of strings (char arrays) of the installed programs.

Charlie Benger-Stevenson
Hart Hill IT Ltd
 
Win API (Microsoft) would have been a better place to ask about stuff like this.

chigley said:
Can anyone show me how to scoop the data out of the buffer and into a char array?
I'm not sure what you mean? Your buffer is a char array. Or are you talking about a different buffer?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top