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.

87 lines
2.1 KiB

  1. #include <pch.hxx>
  2. #ifndef MAC
  3. #include <BadStrFunctions.h>
  4. #pragma warning (disable: 4127) // conditional expression is constant
  5. #define MAXKEYNAME 256
  6. #define MAXVALUENAME_LENGTH MAXKEYNAME
  7. #define MAXDATA_LENGTH 16L*1024L
  8. /*******************************************************************************
  9. *
  10. * CopyRegistry
  11. *
  12. * DESCRIPTION:
  13. *
  14. * PARAMETERS:
  15. * hSourceKey,
  16. * hDestinationKey,
  17. *
  18. *******************************************************************************/
  19. // static because CopyRegistry recurses - don't use too much stack
  20. static CHAR g_KeyNameBuffer[MAXKEYNAME];
  21. static CHAR g_ValueNameBuffer[MAXVALUENAME_LENGTH];
  22. static BYTE g_ValueDataBuffer[MAXDATA_LENGTH];
  23. OESTDAPI_(VOID) CopyRegistry(HKEY hSourceKey, HKEY hDestinationKey)
  24. {
  25. DWORD EnumIndex;
  26. DWORD cbValueName;
  27. DWORD cbValueData;
  28. DWORD Type;
  29. HKEY hSourceSubKey;
  30. HKEY hDestinationSubKey;
  31. //
  32. // Copy all of the value names and their data.
  33. //
  34. EnumIndex = 0;
  35. while (TRUE) {
  36. cbValueName = sizeof(g_ValueNameBuffer);
  37. cbValueData = MAXDATA_LENGTH;
  38. if (RegEnumValue(hSourceKey, EnumIndex++, g_ValueNameBuffer,
  39. &cbValueName, NULL, &Type, g_ValueDataBuffer, &cbValueData) !=
  40. ERROR_SUCCESS)
  41. break;
  42. RegSetValueEx(hDestinationKey, g_ValueNameBuffer, 0, Type,
  43. g_ValueDataBuffer, cbValueData);
  44. }
  45. //
  46. // Copy all of the subkeys and recurse into them.
  47. //
  48. EnumIndex = 0;
  49. while (TRUE) {
  50. if (RegEnumKey(hSourceKey, EnumIndex++, g_KeyNameBuffer, MAXKEYNAME) !=
  51. ERROR_SUCCESS)
  52. break;
  53. if (RegOpenKey(hSourceKey, g_KeyNameBuffer, &hSourceSubKey) ==
  54. ERROR_SUCCESS) {
  55. if (RegCreateKey(hDestinationKey, g_KeyNameBuffer,
  56. &hDestinationSubKey) == ERROR_SUCCESS) {
  57. CopyRegistry(hSourceSubKey, hDestinationSubKey);
  58. RegCloseKey(hDestinationSubKey);
  59. }
  60. RegCloseKey(hSourceSubKey);
  61. }
  62. }
  63. }
  64. #endif // !MAC