Query Registry for Specific Value

Hi,

Using C++ I need some code to find a specific value of a key.

So for example, if I have ...\....\....\...\IBM

Inside that folder one of the keys is called Vaild.  I need to get the 'Data' or value back.

How would you go about this?
LVL 2
corduroy9Asked:
Who is Participating?
 
jkrCommented:
Um, the above assumes that "Valid" is a DWORD value - if it is a string, the following would work:

   HKEY hKey = NULL;
   REGSAM sam = KEY_ALL_ACCESS;
   char* pszKey = "...\\....\\....\\...\\IBM";

   if ( ERROR_SUCCESS != RegOpenKeyEx ( HKEY_LOCAL_MACHINE, pszKey, 0, sam, &hKey)) {

      return; // nothing to do...
   }

   char acValue [ 255];
   DWORD dwType = REG_SZ;
   DWORD dwSize =255;

   if ( ERROR_SUCCESS == RegQueryValueEx (
                                hKey,
                                "Valid",
                                NULL,
                                &dwType,
                                ( LPBYTE) acValue,
                                &dwSize)
                               ) {

   }

   RegCloseKey ( hKey);

}

Oh, and the key name should be changed to what it actually is, also whther it is under HKEY_LOCAL_MACHINE or under an other of the predefined root keys.
0
 
jkrCommented:
You could use

   REGSAM sam = KEY_ALL_ACCESS;
   char* pszKey = "...\\....\\....\\...\\IBM";

   if ( ERROR_SUCCESS != RegOpenKeyEx ( HKEY_LOCAL_MACHINE, pszKey, 0, sam, &hKey)) {

      return; // nothing to do...
   }

   DWORD dwType = REG_DWORD;
   DWORD dwSize = sizeof ( DWORD);
   DWORD dwValue;

   if ( ERROR_SUCCESS == RegQueryValueEx (
                                hKey,
                                "Valid",
                                NULL,
                                &dwType,
                                ( LPBYTE) &dwValue,
                                &dwSize)
                               ) {

   }

   RegCloseKey ( hKey);

}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.