Recusively delete registry keys
Hello,
I've been trying to delete registry keys, including all their subkeys, without resorting to SHDeleteKey (Which isn't directly Windows 95 compatible). So far I've come up with:-
Code:
int DeleteKey(HKEY hKey, char *szSubKey)
{
char szKeyDelete[255];
unsigned long ulSize = 255;
DWORD dwIndex = 0;
HKEY hKeySub;
if (!RegOpenKeyEx(hKey, szSubKey, 0, DELETE | KEY_ENUMERATE_SUB_KEYS, &hKeySub))
{
while (!RegEnumKeyEx(hKeySub, dwIndex, szKeyDelete, &ulSize, NULL, NULL, NULL, NULL))
{
DeleteKey(hKeySub, szKeyDelete);
ulSize = 255;
dwIndex++;
}
RegCloseKey(hKeySub);
RegDeleteKey(hKey, szSubKey);
return TRUE;
}
else
return FALSE;
}
This manages to delete just one of the main subkeys of a key I'm trying to delete. :(
Is there anything here that might be problematic or wrong that I'm not seeing?