Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching the System Registry 1

Status
Not open for further replies.

perplexd

Programmer
May 9, 2002
154
US
Hi,

I'm pretty new to this c++ programming...did Java before - its so much easier to find information out about!! Anyway...

I need to find an entry in the system registry, so that I can write a few files to the correct location. Searching on the net has produced nothing but huge packages which I must implement. I'm sure there must be a way to reference the registry in no more than a few lines - seems like a pretty essential task to me!

Thanks
 
>> I need to find an entry in the system registry

>> I'm sure there must be a way to reference the registry in no more than a few
>> lines - seems like a pretty essential task to me!

Yes, maybe… do you need to search for data in the entire registry or you already know where (what key) you need to read data from?

To read from a key/value in the registry you can use the ATL CRegKey class, it is very simple to use for reading.

If you need to search the registry, there is no built in API for searching that I am aware of. Since it is hierarchal data you should be able to author a relatively simple algorithm using recursion to perform searches.

>> did Java before - its so much easier to find information out about

Windows Platform documentation for API’s like the Registry API can be found at


-pete
 
I used code similar to this to get data back from the registry.
You may need a recursive function to get data back if you need to find the location dynamically

Code:
#define MAX_KEY_LEN 256
...
...
void someFunction()
{
  HKEY	hKey ;
  char szKeyValue[MAX_KEY_LEN]={0};//will hold the results from the key query
  CString strTemp		= "";
  CString strRegKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\MyRegKey";//or whatever
  DWORD   dwType		= 0;
  DWORD   dwSize		= sizeof ( szKeyValue );

  if ( RegOpenKey ( HKEY_LOCAL_MACHINE, strRegKey, &hKey ) == ERROR_SUCCESS )
  {
    if ( RegQueryValueEx ( hKey, 
                           _T(BACKUP_REG_LEVEL),
                           NULL,
                           &dwType,
                           (unsigned char*)szKeyValue,
                           &dwSize ) == ERROR_SUCCESS
        )
    {
      //do some processing
...
...
    }
  }
}

Go not to cats for advice for they will just walk over the keyboard
 
I do know exactly what key I am looking for - sorry that was badly worded. I'm just retreiving data from a key.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top