Posted By

jimfred on 06/21/10


Tagged

mfc


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

khouser


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


 / Published in: C++
 

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( HKEYLOCALMACHINE, "SOFTWARE\Microsoft\Internet Explorer", "Version" );

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

  1. // Get Registry string value.
  2. // Example usage:
  3. // GetRegString( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Internet Explorer", "Version" );
  4. // GetRegString( HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Mozilla Firefox", "CurrentVersion" );
  5. CString GetRegString( HKEY hKeyArg, LPCSTR keyNameArg, LPCSTR valNameArg )
  6. {
  7. CString s;
  8. CRegKey k;
  9. k.Open( HKEY_LOCAL_MACHINE, keyNameArg );
  10. ULONG len = 255;
  11. k.QueryStringValue( valNameArg, s.GetBufferSetLength( len ), &len );
  12. s.ReleaseBuffer();
  13. return s;
  14. }

Report this snippet  

You need to login to post a comment.