1 open a registry key/query registry/modify value
HKEY hKey;
LPCTSTR keyStr1 = "Software//Microsoft//Windows//CurrentVersion//Policies//Explorer//";
DWORD dwType;
DWORD dwValue;
DWORD dwSize;
if(::RegOpenKeyEx(HKEY_CURRENT_USER,keyStr1, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
{
dwType = REG_DWORD;
dwSize = sizeof(DWORD);
if(::RegQueryValueEx(hKey,"ClearRecentDocsonExit",NULL,&dwType,(LPBYTE)&dwValue,&dwSize) == ERROR_SUCCESS)
{
if(dwValue == 1)
{
dwValue = 0;
if(::RegSetValueEx(hKey,"ClearRecentDocsonExit",NULL,REG_DWORD,(CONST BYTE *)&dwValue,sizeof(DWORD)) == ERROR_SUCCESS)
{
return FALSE;
}
else
{
return FALSE;
}
}
}
}
else
{
}
RegCloseKey(hKey);
2 create registry key/create a new value and set a value for the key
HKEY hKey;
LPCTSTR keyStr1 = "Software//Microsoft//Windows//CurrentVersion//Policies//Test//";
DWORD dwDescription;
DWORD dwValue = 1;
if(::RegCreateKeyEx(HKEY_CURRENT_USER,keyStr1, 0, NULL,REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey,&dwDescription) == ERROR_SUCCESS)
{
if(::RegSetValueEx(hKey,"ClearRecentDocsonExit",NULL,REG_DWORD,(CONST BYTE *)&dwValue,sizeof(DWORD)) == ERROR_SUCCESS)
{
return FALSE;
}
else
{
return FALSE;
}
}
else
{
}
RegCloseKey(hKey);