Return to Snippet

Revision: 27691
at June 21, 2010 13:44 by jimfred


Initial Code
// Get Registry string value.
// Example usage:
//   GetRegString( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer", "Version" );
//   GetRegString( HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Mozilla Firefox", "CurrentVersion" );
CString GetRegString( HKEY hKeyArg, LPCSTR keyNameArg, LPCSTR valNameArg )
{
   CString s;
   CRegKey k;
   k.Open( HKEY_LOCAL_MACHINE, keyNameArg );
   ULONG len = 255;
   k.QueryStringValue( valNameArg, s.GetBufferSetLength( len ),  &len );
   s.ReleaseBuffer();
   return s;
}

Initial URL

                                

Initial Description
RegGetValue apparently isn't available in XP SP2. I tried and got an error. MSDN implied it wasn't available.

Example usage to get versions of browsers:

GetRegString( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer", "Version" );

GetRegString( HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Mozilla Firefox", "CurrentVersion" );

Initial Title
Get a Registry string value as a CString, MFC. Examples to get version of browsers.

Initial Tags

                                

Initial Language
C++