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.

92 lines
2.1 KiB

  1. /*
  2. *
  3. * Copyright (c) Microsoft Corporation. All rights reserved.
  4. *
  5. * pcommon.h
  6. *
  7. * Common routines for policy code.
  8. */
  9. //*************************************************************
  10. //
  11. // RegDelnode()
  12. //
  13. // Deletes a registry key and all it's subkeys.
  14. //
  15. // hKeyRoot Root key
  16. // lpSubKey SubKey to delete
  17. //
  18. //*************************************************************
  19. DWORD
  20. RegDelnode(
  21. IN HKEY hKeyRoot,
  22. IN PWCHAR pwszSubKey
  23. )
  24. #ifdef PCOMMON_IMPL
  25. {
  26. HKEY hSubKey = 0;
  27. PWCHAR pwszChildSubKey = 0;
  28. DWORD MaxCchSubKey;
  29. DWORD Status;
  30. if ( ! pwszSubKey )
  31. return ERROR_SUCCESS;
  32. Status = RegDeleteKey( hKeyRoot, pwszSubKey );
  33. if ( ERROR_SUCCESS == Status )
  34. return ERROR_SUCCESS;
  35. Status = RegOpenKeyEx( hKeyRoot, pwszSubKey, 0, KEY_READ, &hSubKey );
  36. if ( Status != ERROR_SUCCESS )
  37. return (Status == ERROR_FILE_NOT_FOUND) ? ERROR_SUCCESS : Status;
  38. Status = RegQueryInfoKey( hSubKey, 0, 0, 0, 0, &MaxCchSubKey, 0, 0, 0, 0, 0, 0 );
  39. if ( ERROR_SUCCESS == Status )
  40. {
  41. MaxCchSubKey++;
  42. pwszChildSubKey = (PWCHAR) LocalAlloc( 0, MaxCchSubKey * sizeof(WCHAR) );
  43. if ( ! pwszChildSubKey )
  44. Status = ERROR_OUTOFMEMORY;
  45. }
  46. for (;(ERROR_SUCCESS == Status);)
  47. {
  48. DWORD CchSubKey;
  49. FILETIME FileTime;
  50. CchSubKey = MaxCchSubKey;
  51. Status = RegEnumKeyEx(
  52. hSubKey,
  53. 0,
  54. pwszChildSubKey,
  55. &CchSubKey,
  56. NULL,
  57. NULL,
  58. NULL,
  59. &FileTime );
  60. if ( ERROR_NO_MORE_ITEMS == Status )
  61. {
  62. Status = ERROR_SUCCESS;
  63. break;
  64. }
  65. if ( ERROR_SUCCESS == Status )
  66. Status = RegDelnode( hSubKey, pwszChildSubKey );
  67. }
  68. RegCloseKey( hSubKey );
  69. LocalFree( pwszChildSubKey );
  70. return RegDeleteKey( hKeyRoot, pwszSubKey );
  71. }
  72. #else
  73. ;
  74. #endif