You can easily write your own routine for RegDeleteTree, or RegDeleteTreeW and RegDeleteTreeA!Alternatively you can also use SHDeleteKeyA or SHDeleteKeyW ! The provided C++ code is a function that is used to recursively delete a registry key and all its child keys. Here is a short description of the code with comments in German:
BOOL RecurseDeleteKey(HKEY hKey, LPCTSTR lpszKey) { try { DWORD dw; HKEY hNewKey; LONG lRes; // Attempt to create a new registry key under the provided main key. // Using the main key 'hKey' and the key name 'lpszKey'. if (RegCreateKeyEx(hKey, (LPCTSTR)lpszKey, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &hNewKey, &dw) == ERROR_SUCCESS) { TCHAR szBuffer[256]; DWORD dwSize = 256; FILETIME time; // Loop through all subkeys of the newly created key. while (RegEnumKeyEx(hNewKey, 0, szBuffer, &dwSize, NULL, NULL, NULL, &time) == ERROR_SUCCESS) { // Recursive call to delete the subkey. lRes = RecurseDeleteKey(hNewKey, szBuffer); if (lRes != ERROR_SUCCESS) return lRes; dwSize = 256; } } // Delete the main key and all its subkeys. return RegDeleteKey(hKey, lpszKey); } catch (...) { return FALSE; } } This code uses the Windows registry functions to delete registry keys and their child keys. The RecurseDeleteKey function is called recursively to delete all child keys before deleting the master key. Note that the code is wrapped in a try-catch block to catch possible exceptions and return FALSE if an exception occurs. FAQ 22: Updated on: 4 September 2024 12:20 |