×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

RegQueryValueEx driving me mad

RegQueryValueEx driving me mad

RegQueryValueEx driving me mad

(OP)
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
www.harthill-it.co.uk
 

RE: RegQueryValueEx driving me mad

(OP)
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
www.harthill-it.co.uk
 

RE: RegQueryValueEx driving me mad

Win API (Microsoft) would have been a better place to ask about stuff like this.

Quote (chigley):

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?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close