Reputation: 5264
I have a key in registry name my_software.
I want to delete it from vc++ coding.
CRegKey key;
LPCSTR lpszKey = "SOFTWARE\\my_software";
key.m_hKey = HKEY_LOCAL_MACHINE;
LONG lRes = key.Open(key.m_hKey, lpszKey);
LONG err = key.DeleteSubKey(lpszKey);
When I debug the code err has value 0x00000002. When I saw in winerror.h file it means ERROR_FILE_NOT_FOUND
Upvotes: 0
Views: 3111
Reputation: 1197
Like so:
bool DeleteValueKey(HKEY hKeyRoot, std::string Subkey, std::string ValueKey)
{
HKEY hKey = NULL;
bool bReturn = false;
if (RegOpenKeyEx(hKeyRoot, Subkey.c_str(), 0, KEY_SET_VALUE , &hKey) == ERROR_SUCCESS)
{
if (RegDeleteKey(hKey, ValueKey.c_str() ) == ERROR_SUCCESS)
{
bReturn = true;
}
}
if(hKey != NULL){RegCloseKey(hKey);}
return bReturn;
}
Upvotes: 1