Click to See Complete Forum and Search --> : Windows SDK Registry: How can I write data to the registry?


Andreas Masur
May 23rd, 2003, 04:03 PM
Q: How can I write data to the registry?

A:


HKEY hKey;

if(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"System\\CurrentControlSet\\Control\\Windows",
0,
KEY_SET_VALUE,
&hKey) == ERROR_SUCCESS)
{
DWORD dwValue = 245;

// Set value
if(::RegSetValueEx(hKey,
"NameOfValue",
0,
REG_DWORD,
reinterpret_cast<BYTE *>(&dwValue),
sizeof(dwValue)) != ERROR_SUCCESS)
{
// Close key
::RegCloseKey(hKey);

// Error handling;
}

// Close key
::RegCloseKey(hKey);
}
else
// Error handling;

<br>