Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
912 B

  1. #include <windows.h>
  2. LONG RegDeleteKeyRecursively(HKEY hkRootKey, PCSTR pcszSubKey)
  3. {
  4. LONG lErr;
  5. if ((lErr = RegDeleteKey(hkRootKey, pcszSubKey)) != ERROR_SUCCESS)
  6. {
  7. HKEY hkSubKey;
  8. // delete the key recursively
  9. if ((lErr = RegOpenKeyEx(hkRootKey, pcszSubKey, 0, KEY_READ | KEY_WRITE, &hkSubKey)) == ERROR_SUCCESS)
  10. {
  11. CHAR szSubKeyName[MAX_PATH + 1];
  12. DWORD dwIndex;
  13. if ((lErr = RegQueryInfoKey(hkSubKey, NULL, NULL, NULL, &dwIndex, NULL, NULL, NULL, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS)
  14. while (RegEnumKey(hkSubKey, --dwIndex, szSubKeyName, sizeof(szSubKeyName)) == ERROR_SUCCESS)
  15. RegDeleteKeyRecursively(hkSubKey, szSubKeyName);
  16. RegCloseKey(hkSubKey);
  17. lErr = RegDeleteKey(hkRootKey, pcszSubKey);
  18. }
  19. }
  20. return lErr;
  21. }