Sign in to follow this  
bikola_p

Registry Reading

Recommended Posts

bikola_p    100
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.

Share this post


Link to post
Share on other sites
Sailorstick    142

/***********************************************************************************************
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...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this