Click here to Skip to main content
15,888,610 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Saving information in registry 'HKEY_LOCAL_MACHINE' Pin
JensB12-Jan-04 0:13
JensB12-Jan-04 0:13 
GeneralRe: Saving information in registry 'HKEY_LOCAL_MACHINE' Pin
Jijo.Raj12-Jan-04 1:38
Jijo.Raj12-Jan-04 1:38 
GeneralRe: Saving information in registry 'HKEY_LOCAL_MACHINE' Pin
JensB12-Jan-04 2:09
JensB12-Jan-04 2:09 
GeneralRe: Saving information in registry 'HKEY_LOCAL_MACHINE' Pin
Jijo.Raj12-Jan-04 2:13
Jijo.Raj12-Jan-04 2:13 
GeneralRe: Saving information in registry 'HKEY_LOCAL_MACHINE' Pin
JensB12-Jan-04 4:47
JensB12-Jan-04 4:47 
GeneralRe: Saving information in registry 'HKEY_LOCAL_MACHINE' Pin
Jijo.Raj12-Jan-04 5:46
Jijo.Raj12-Jan-04 5:46 
GeneralRe: Saving information in registry 'HKEY_LOCAL_MACHINE' Pin
Anonymous12-Jan-04 20:11
Anonymous12-Jan-04 20:11 
GeneralRe: Saving information in registry 'HKEY_LOCAL_MACHINE' Pin
Jijo.Raj13-Jan-04 2:26
Jijo.Raj13-Jan-04 2:26 
hai Jens,
Use the following code. I got it from my friend - John AV, who is a registry expert. Big Grin | :-D Okey. First be thorough with the code, make any changes if you need, then use it.

const static int nMaxValueNameSize = MAX_PATH;
const static int nMaxValueValueSize = 4096;
const static int nMaxClassSize = MAX_PATH;
const static int nMaxKeyNameSize = MAX_PATH;

BOOL CopyRegistryKey(HKEY hkRootFrom, const CString& strFromPath, HKEY hkRootTo, const CString& strToPath) 
{
	HKEY hkFrom;
	LONG res = ::RegOpenKeyEx(hkRootFrom, strFromPath, 0, KEY_READ, &hkFrom);
	if (ERROR_SUCCESS != res) {
		return FALSE;	
	}
	HKEY hkTo;
	res = ::RegCreateKeyEx(hkRootTo, strToPath, 0, 0, REG_OPTION_NON_VOLATILE, KEY_WRITE, 0, &hkTo, 0);
	if (ERROR_SUCCESS != res) {
		::RegCloseKey(hkFrom);
		return FALSE;	
	}
	BOOL bRes = CopyKeys(hkFrom, hkTo) && CopyValues(hkFrom, hkTo);

	::RegCloseKey(hkFrom);
	::RegCloseKey(hkTo);

	return bRes;
}

static BOOL CopyKeys(HKEY hkFrom, HKEY hkTo) 
{
	TCHAR lpstrName[nMaxKeyNameSize];
	TCHAR lpstrClass[nMaxClassSize];

	for (int i = 0;;i++) {
		DWORD nNameSize = nMaxKeyNameSize;
		DWORD nClassSize = nMaxClassSize;
		LONG res = ::RegEnumKeyEx(hkFrom, i, lpstrName, &nNameSize, 0, lpstrClass, &nClassSize, 0);
		if (ERROR_NO_MORE_ITEMS == res) {
			break;
		}
		HKEY hkNew;
		res = ::RegCreateKeyEx(hkTo, lpstrName, 0, lpstrClass, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hkNew, 0); ;
		if (ERROR_SUCCESS != res) {
			return FALSE;		
		}
		::RegCloseKey(hkNew);
		BOOL bRes = CopyRegistryKey(hkFrom, lpstrName, hkTo, lpstrName);
		if (! bRes) {
			return FALSE;		
		}
	}

	return TRUE;
}

static BOOL CopyValues(HKEY hkFrom, HKEY hkTo) 
{
	TCHAR lpstrName[nMaxValueNameSize];
	BYTE pValue[nMaxValueValueSize];

	for (int i = 0;;i++) {
		DWORD nType;
		DWORD nNameSize = nMaxValueNameSize;
		DWORD nValueSize = nMaxValueValueSize;
		LONG res = ::RegEnumValue(hkFrom, i, lpstrName, &nNameSize, 0, &nType, pValue, &nValueSize);
		if (ERROR_NO_MORE_ITEMS == res) {
			break;
		}
		res = ::RegSetValueEx(hkTo, lpstrName, 0, nType, pValue, nValueSize);
		if (ERROR_SUCCESS != res) {
			return FALSE;		
		}
	}

	return TRUE;
}


Hope this helped you.

Regards,
Jijo. Wink | ;)

________________________________

Yesterday is history,
Tomorrow is a mystery,
But today is a present.
GeneralSpying on HTML Pin
Monty211-Jan-04 22:58
Monty211-Jan-04 22:58 
GeneralRe: Spying on HTML Pin
22491712-Jan-04 0:24
22491712-Jan-04 0:24 
GeneralSomething Like this Pin
Monty212-Jan-04 1:13
Monty212-Jan-04 1:13 
GeneralRe: Spying on HTML Pin
ohadp12-Jan-04 2:22
ohadp12-Jan-04 2:22 
GeneralRe: Spying on HTML Pin
Monty212-Jan-04 2:31
Monty212-Jan-04 2:31 
GeneralRemote Machine Processes Pin
Mahesh Varma11-Jan-04 22:34
Mahesh Varma11-Jan-04 22:34 
General_beginthread Pin
murali_utr11-Jan-04 22:32
murali_utr11-Jan-04 22:32 
GeneralRe: _beginthread Pin
Mahesh Varma11-Jan-04 22:54
Mahesh Varma11-Jan-04 22:54 
GeneralShow PropertyPage of an activeX control Pin
hajer11-Jan-04 22:31
hajer11-Jan-04 22:31 
GeneralRe: About the PostThreadMessage(...)??? Pin
Michael Dunn11-Jan-04 21:04
sitebuilderMichael Dunn11-Jan-04 21:04 
GeneralRe: About the PostThreadMessage(...)??? Pin
KarstenK12-Jan-04 4:25
mveKarstenK12-Jan-04 4:25 
GeneralListBox in ComboBox Pin
Tonnystar11-Jan-04 20:51
Tonnystar11-Jan-04 20:51 
GeneralRe: ListBox in ComboBox Pin
Jijo.Raj11-Jan-04 21:05
Jijo.Raj11-Jan-04 21:05 
GeneralRe: ListBox in ComboBox Pin
22491711-Jan-04 21:53
22491711-Jan-04 21:53 
GeneralRe: ListBox in ComboBox Pin
Tonnystar19-Jan-04 4:48
Tonnystar19-Jan-04 4:48 
GeneralGetExtent -> SetExtent Pin
El'Cachubrey11-Jan-04 20:27
El'Cachubrey11-Jan-04 20:27 
GeneralHi Pin
Ruchit Sharma11-Jan-04 20:19
Ruchit Sharma11-Jan-04 20:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.