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

Changing the Root Registry Key

Status
Not open for further replies.

gscti

Programmer
May 9, 2002
2
US
Hi,

Does anyone know of a way to change the root registry key from HKEY_CURRENT_USER to HKEY_LOCAL_MACHINE.

I do the following code:
SetRegistryKey(_T("CTI"));
m_pszProfileName = _tcsdup(_T("TIP Medical"));
LoadStdProfileSettings();

CString strTemp;
strTemp = GetProfileString(_T("Paths"), _T("TIPDir"));

strTemp will always get the key value for TIPDir from
HKEY_CURRENT_USER\Software\CTI\TIP Medical\Paths\TIPDir.

GetProfileString() calls GetSectionKey() which calls GetAppRegistryKey().

GetAppRegistryKey()calls RegOpenKeyEx() always with the HKEY_CURRENT_USER root key.


HKEY CWinApp::GetAppRegistryKey()
{
ASSERT(m_pszRegistryKey != NULL);
ASSERT(m_pszProfileName != NULL);

HKEY hAppKey = NULL;
HKEY hSoftKey = NULL;
HKEY hCompanyKey = NULL;
if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("software"), 0, KEY_WRITE|KEY_READ,
&hSoftKey) == ERROR_SUCCESS)
{
DWORD dw;
if (RegCreateKeyEx(hSoftKey, m_pszRegistryKey, 0, REG_NONE,
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
&hCompanyKey, &dw) == ERROR_SUCCESS)
{
RegCreateKeyEx(hCompanyKey, m_pszProfileName, 0, REG_NONE,
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
&hAppKey, &dw);
}
}
if (hSoftKey != NULL)
RegCloseKey(hSoftKey);
if (hCompanyKey != NULL)
RegCloseKey(hCompanyKey);

return hAppKey;
}


Any help will be appreciated.

Thanks
Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top