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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Registry reading and writing

Status
Not open for further replies.

Robertus

Programmer
Feb 16, 2001
81
RO
How do I use CRegKey so that I could create multiple levels of keys and subkeys, in registry?
I would like something like this:

HKEY_LOCAL_MACHINE
- Robertus(key)
-About(subkey of Robertus)
-Age xx (int value)
-Height zz (int value)
-Marital Status: "vv" (string value)
-Skills(subkey of Robertus)
- AAA(subkey of Skills)
- BBB (subkey of AAA)
- field1 87 (long value)
- field2 67 (long value)

And then how should I get the value that "hides" under BBB - field1, for example?
(I would like a piece of code if possible, please)

Thanks a lot, even if you answer me or not!
 
Hi

To access

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main

pass the strKey = "Software\\Microsoft\\Internet Explorer\\Main" to the function GetRegistryKey or SetRegistryKey.
Here the first parameter of RegOpenKeyEx is hard-coded but you can also pass it as a parameter of a modified version of the proposed GetRegistryKey function

HTH
Thierry
EMail: Thierry.Marneffe@swing.be


CString CFoo::GetRegistryKey( CString strKey, CString strName)
{

CString str;
HKEY hKey; // Handle to Registry Key

// Open the Key in the Registry

long lResult = RegOpenKeyEx( HKEY_CURRENT_USER, strKey, 0, KEY_ALL_ACCESS, &hKey);

// Check for Error

if ( lResult == ERROR_SUCCESS)
{
char szBuffer[100];
DWORD dwBufferSize = 100;
DWORD dwType;

long lQueryResult =
RegQueryValueEx( hKey, strName, 0, &dwType, (LPBYTE) szBuffer, &dwBufferSize);

// Store Data ( if available)

if ( lQueryResult == ERROR_SUCCESS)
str = CString( szBuffer, ( int) dwBufferSize);
}
CloseHandle( hKey);

return str;
}

void CFoo::SetRegistryKey( CString strKey, CString strName, CString strNewValue)
{

HKEY hKey; // Handle to Registry Key

// Open the Key in the Registry

long lResult = RegOpenKeyEx( HKEY_CURRENT_USER, strKey, 0,
KEY_ALL_ACCESS, &hKey);

// Check for Error

if ( lResult == ERROR_SUCCESS)
{
char szBuffer[100];
DWORD dwBufferSize = 100;

// Set New Value
strnset( szBuffer, '\0', 100);
strcpy( szBuffer, strNewValue);

RegSetValueEx( hKey, strName, 0, REG_EXPAND_SZ,
( LPBYTE) szBuffer, strlen( szBuffer) + 1);
}
CloseHandle( hKey);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top