blob: 4603251b4c6bb0b7eccb89c0d5accd68a0e91bb1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#include <windows.h>
// delete the whole sub key
LONG win_reg_deltree(HKEY hParentKey, const TCHAR * strKeyName){
TCHAR szSubKeyName[MAX_PATH];
HKEY hCurrentKey;
LONG dwResult;
if ((dwResult = RegOpenKey(hParentKey, strKeyName, &hCurrentKey)) == ERROR_SUCCESS){
// Remove all subkeys of the key to delete
while ((dwResult = RegEnumKey(hCurrentKey, 0, szSubKeyName, 255)) == ERROR_SUCCESS){
if((dwResult = win_reg_deltree(hCurrentKey, szSubKeyName)) != ERROR_SUCCESS)break;
}
// If all went well, we should now be able to delete the requested key
if((dwResult == ERROR_NO_MORE_ITEMS) || (dwResult == ERROR_BADKEY)){
dwResult = RegDeleteKey(hParentKey, strKeyName);
}
RegCloseKey(hCurrentKey);
}
return dwResult;
}
|