Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Obtaining Registry Values

Posted on 1998-07-22
3
Medium Priority
?
413 Views
Last Modified: 2013-11-20
I need to be able to obtain any value from any key in the registry.  I currently use the SetRegistryKey function along with the GetProfileInt, GetProfileString, WriteProfileInt, and WriteProfileString functions, but this only looks in an area of the registry specific to that application. Specifically, I need the value of the key:

HKEY_CURRENT_USER\Software\Cimple Systems\BasePath

Where BasePath is a String (i.e. "D:\Cimple" ).  How do I do this?  Also, how would I then change it if I wanted to?
0
Comment
Question by:ardolino
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 210 total points
ID: 1319613
//
// Read a value from the Windows Registry
//
char *ReadRegistryValue(HKEY HK, char *Node, char *Key)
{
    HKEY hKey;
      DWORD s_len;
      long regStatus;

      static unsigned char *kval = NULL;

    if(
        RegOpenKeyEx(
            HK,
            Node,
            0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS){

            // Get the length of the data value first
            if((regStatus = RegQueryValueEx(hKey, Key, NULL, NULL, NULL, &s_len)) != ERROR_SUCCESS){
                return NULL;
            }

            // Make space to hold it
            if(kval != NULL){
                  delete [] kval;
            }

            kval = new unsigned char[s_len];

            // Get the actual data from registry
            if(RegQueryValueEx(hKey, Key, NULL, NULL, kval, &s_len) != ERROR_SUCCESS){
                return NULL;
            }
        RegCloseKey(hKey);
            return (char *)kval;
    }
    else{
            return NULL;
    }
}
0
 
LVL 7

Expert Comment

by:psdavis
ID: 1319614
Sorry for butting in...

Although the above answer does work, you can change your "CSimple Systems" with CWinApp::m_pszExeName and CWinApp::m_pszProfileName.  I have included my override functions if it would help.

// In the CWinApp::InitInstance

   SetRegistryKeyName    ( _T( "The Phoenix Group" ));
   SetRegistryProfileName( );


void CWinAppEx::SetRegistryKeyName( const char* pszRegistryKey )
{
// First free the string allocated by MFC at CWinApp startup.
// The string is allocated before InitInstance is called.

   free( (void*) m_pszRegistryKey );

// Change the name of the registry key.
// The CWinApp destructor will free the memory.

   if( pszRegistryKey == NULL || *pszRegistryKey == NULL )
      m_pszRegistryKey = _tcsdup( _T( "CompanyName" ));
   else
      m_pszRegistryKey = _tcsdup( pszRegistryKey );
   }

void CWinAppEx::SetRegistryExeName( const char* pszExeName )
{
// First free the string allocated by MFC at CWinApp startup.
// The string is allocated before InitInstance is called.

   free( (void*) m_pszExeName );

// Change the name of the registry key.
// The CWinApp destructor will free the memory.

   if( pszExeName == NULL || *pszExeName == NULL )
      m_pszExeName = _tcsdup( _T( "ExeName" ));
   else
      m_pszExeName = _tcsdup( pszExeName );
   }

void CWinAppEx::SetRegistryProfileName( const char* pszProfileName )
{
// First free the string allocated by MFC at CWinApp startup.
// The string is allocated before InitInstance is called.

   free( (void*) m_pszProfileName );

// Change the name of the registry key.
// The CWinApp destructor will free the memory.

   if( pszProfileName == NULL || *pszProfileName == NULL )
      m_pszProfileName = _tcsdup( _T( "ExeName\\Profile" ));
   else
      m_pszProfileName = _tcsdup( pszProfileName );
   }

Phillip
0
 

Author Comment

by:ardolino
ID: 1319615
Thanks.  I checked out the www.codegyru.com (I think thats the name) web site and found a CRegistry class that I can use (freeware).  Thanks anyway.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question