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


/ Published in: C++
Save to your folder(s)

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" );


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.