Registry Reading

Started by
4 comments, last by iMalc 18 years, 4 months ago
Hey guys, after searching and looking through some tutorials, i cant seem to find a simple example of reading from an existing registry key, or writing a creating a new registry key. This is one of those things, I would expect is well documented and easy to pick up, but im finding it pretty difficult.
Advertisement
Is it not CreateRegisteryKey()?
RegCreateKeyEx
RegQueryValueEx
/***********************************************************************************************Get keys function	written by Aaron Holland	14 Mar 2000		This function returns a key value 		KeyName:	A sub key.   (can contain \'s)	AttribName:	The attribute name.		returns:	A string value of the Data***********************************************************************************************/char* GetRegSetting(HKEY TopLevel, LPCSTR KeyName, LPSTR AttribName){		//declare variables	long KeySize = 255;	HKEY KeyPointer;	if(DEBUG){		printf("KeyName: %s\n", KeyName);		printf("AttribName: %s\n", AttribName);	}	RegOpenKeyEx(TopLevel, KeyName, NULL, KEY_READ, &KeyPointer);	RegQueryValueEx(KeyPointer, AttribName, NULL, NULL, (LPBYTE)output, (LPDWORD)&KeySize);	RegCloseKey(KeyPointer);	if(DEBUG){		printf("Read registry value: %s\n", output);	}		return output;}/***********************************************************************************************Set keys function	written by Aaron Holland	1 Nov 2000		This function sets a key value 		KeyName:	A sub key.   (can contain \'s)	AttribName:	The attribute name.	Value:		A value for the attribute***********************************************************************************************/void SetRegSetting(HKEY TopLevel, LPCSTR KeyName, LPSTR AttribName, const BYTE* Value, int Size){		//declare variables	DWORD KeySize = (DWORD)Size;	HKEY KeyPointer;	if(DEBUG){		printf("KeyName: %s\n", KeyName);		printf("AttribName: %s\n", AttribName);	}	RegOpenKeyEx(TopLevel, KeyName, NULL, KEY_WRITE, &KeyPointer);	RegSetValueEx(KeyPointer, AttribName, NULL, REG_SZ, Value, KeySize);	RegCloseKey(KeyPointer);	if(DEBUG){		printf("Wrote registry value: \n%s\n", Value);	}}


No keys actually being created here, but should get you started. MSDN for RegOpenKeyEx and there will probably be links to CreateKey etc...
For the creating stuff, Evil Steve has a great post here.
I'm rather fond of ATL's CRegKey myself.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement