Windows SDK Registry: How can I write data to the registry?

Q: How can I write data to the registry?

A: To open the registry key use the function RegOpenKeyEx. To write a vaule from registry use the function RegSetValueEx.

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;

Note: Most of the material in this article is taken from codeguru.com


Recommended Reading :





Personal Loan - Loans - Phoenix Landscaping - Credit Card Consolidation