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.

166 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. copyreg.c
  5. Abstract:
  6. This module provides functions to copy registry keys
  7. Author:
  8. Krishna Ganugapati (KrishnaG) 20-Apr-1994
  9. Notes:
  10. List of functions include
  11. CopyValues
  12. CopyRegistryKeys
  13. Revision History:
  14. --*/
  15. #include <precomp.h>
  16. #pragma hdrstop
  17. #include "clusspl.h"
  18. VOID
  19. CopyValues(
  20. HKEY hSourceKey,
  21. HKEY hDestKey,
  22. PINISPOOLER pIniSpooler
  23. )
  24. /*++
  25. Description: This function copies all the values from hSourceKey to hDestKey.
  26. hSourceKey should be opened with KEY_READ and hDestKey should be opened with
  27. KEY_WRITE.
  28. Returns: VOID
  29. --*/
  30. {
  31. DWORD iCount = 0;
  32. WCHAR szValueString[MAX_PATH];
  33. DWORD dwSizeValueString;
  34. DWORD dwType = 0;
  35. PBYTE pData;
  36. DWORD cbData = 1024;
  37. DWORD dwSizeData;
  38. SplRegQueryInfoKey( hSourceKey,
  39. NULL,
  40. NULL,
  41. NULL,
  42. NULL,
  43. &cbData,
  44. NULL,
  45. NULL,
  46. pIniSpooler );
  47. pData = (PBYTE)AllocSplMem( cbData );
  48. if( pData ){
  49. dwSizeValueString = COUNTOF(szValueString);
  50. dwSizeData = cbData;
  51. while ((SplRegEnumValue(hSourceKey,
  52. iCount,
  53. szValueString,
  54. &dwSizeValueString,
  55. &dwType,
  56. pData,
  57. &dwSizeData,
  58. pIniSpooler
  59. )) == ERROR_SUCCESS ) {
  60. SplRegSetValue( hDestKey,
  61. szValueString,
  62. dwType,
  63. pData,
  64. dwSizeData, pIniSpooler);
  65. dwSizeValueString = COUNTOF(szValueString);
  66. dwType = 0;
  67. dwSizeData = cbData;
  68. iCount++;
  69. }
  70. FreeSplMem( pData );
  71. }
  72. }
  73. BOOL
  74. CopyRegistryKeys(
  75. HKEY hSourceParentKey,
  76. LPWSTR szSourceKey,
  77. HKEY hDestParentKey,
  78. LPWSTR szDestKey,
  79. PINISPOOLER pIniSpooler
  80. )
  81. /*++
  82. Description:This function recursively copies the szSourceKey to szDestKey. hSourceParentKey
  83. is the parent key of szSourceKey and hDestParentKey is the parent key of szDestKey.
  84. Returns: TRUE if the function succeeds; FALSE on failure.
  85. --*/
  86. {
  87. DWORD dwRet;
  88. DWORD iCount;
  89. HKEY hSourceKey, hDestKey;
  90. WCHAR lpszName[MAX_PATH];
  91. DWORD dwSize;
  92. dwRet = SplRegOpenKey(hSourceParentKey,
  93. szSourceKey, KEY_READ, &hSourceKey, pIniSpooler);
  94. if (dwRet != ERROR_SUCCESS) {
  95. return(FALSE);
  96. }
  97. dwRet = SplRegCreateKey(hDestParentKey,
  98. szDestKey, 0, KEY_WRITE, NULL, &hDestKey, NULL, pIniSpooler);
  99. if (dwRet != ERROR_SUCCESS) {
  100. SplRegCloseKey(hSourceKey, pIniSpooler);
  101. return(FALSE);
  102. }
  103. iCount = 0;
  104. memset(lpszName, 0, sizeof(WCHAR)*COUNTOF(lpszName));
  105. dwSize = COUNTOF(lpszName);
  106. while((SplRegEnumKey(hSourceKey, iCount, lpszName,
  107. &dwSize,NULL,pIniSpooler)) == ERROR_SUCCESS) {
  108. CopyRegistryKeys( hSourceKey,
  109. lpszName,
  110. hDestKey,
  111. lpszName,
  112. pIniSpooler );
  113. memset(lpszName, 0, sizeof(WCHAR)*MAX_PATH);
  114. dwSize = COUNTOF(lpszName);
  115. iCount++;
  116. }
  117. CopyValues(hSourceKey, hDestKey, pIniSpooler);
  118. SplRegCloseKey(hSourceKey, pIniSpooler);
  119. SplRegCloseKey(hDestKey, pIniSpooler);
  120. return(TRUE);
  121. }