Solved

Obtaining Registry Values

Posted on 1998-07-22
3
387 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 70 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 183
Is there a simple front-end menu system. 9 141
Way to decrease size of apk file 9 127
Notepad++ Question 11 20
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

742 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