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.

198 lines
7.3 KiB

  1. //-----------------------------------------------------------------------//
  2. //
  3. // File: Reg.h
  4. // Created: Jan 1997
  5. // By: Martin Holladay (a-martih)
  6. // Purpose: Header file for Reg.cpp
  7. // Modification History:
  8. // Created - Jan 1997 (a-martih)
  9. // Aug 1997 - MartinHo - Incremented to 1.01 for bug fixes in:
  10. // load.cpp, unload.cpp, update.cpp, save.cpp & restore.cpp
  11. // Sept 1997 - MartinHo - Incremented to 1.02 for update:
  12. // increased value date max to 2048 bytes
  13. // Oct 1997 - MartinHo - Incremented to 1.03 for REG_MULTI_SZ bug fixes.
  14. // Correct support for REG_MULTI_SZ with query, add and update.
  15. // April 1998 - MartinHo - Fixed RegOpenKey() in Query.cpp to not require
  16. // KEY_ALL_ACCESS but rather KEY_READ.
  17. // June 1998 - MartinHo - Increased LEN_MACHINENAME to 18 to account for the
  18. // leading "\\" characters. (version 1.05)
  19. // Feb 1999 - A-ERICR - added reg dump, reg find, and many bug fixes(1.06)
  20. // April 1999 Zeyong Xu: re-design, revision -> version 2.0
  21. //
  22. //------------------------------------------------------------------------//
  23. #ifndef _REG_H
  24. #define _REG_H
  25. //
  26. // macros
  27. //
  28. __inline BOOL SafeCloseKey( HKEY* phKey )
  29. {
  30. if ( phKey == NULL )
  31. {
  32. ASSERT( 0 );
  33. return FALSE;
  34. }
  35. if ( *phKey != NULL )
  36. {
  37. RegCloseKey( *phKey );
  38. *phKey = NULL;
  39. }
  40. return TRUE;
  41. }
  42. #define ARRAYSIZE SIZE_OF_ARRAY
  43. //
  44. // ROOT Key String
  45. //
  46. #define STR_HKLM L"HKLM"
  47. #define STR_HKCU L"HKCU"
  48. #define STR_HKCR L"HKCR"
  49. #define STR_HKU L"HKU"
  50. #define STR_HKCC L"HKCC"
  51. #define STR_HKEY_LOCAL_MACHINE L"HKEY_LOCAL_MACHINE"
  52. #define STR_HKEY_CURRENT_USER L"HKEY_CURRENT_USER"
  53. #define STR_HKEY_CLASSES_ROOT L"HKEY_CLASSES_ROOT"
  54. #define STR_HKEY_USERS L"HKEY_USERS"
  55. #define STR_HKEY_CURRENT_CONFIG L"HKEY_CURRENT_CONFIG"
  56. //
  57. // error messages
  58. //
  59. // general
  60. #define ERROR_INVALID_SYNTAX GetResString2( IDS_ERROR_INVALID_SYNTAX, 0 )
  61. #define ERROR_INVALID_SYNTAX_EX GetResString2( IDS_ERROR_INVALID_SYNTAX_EX, 0 )
  62. #define ERROR_INVALID_SYNTAX_WITHOPT GetResString2( IDS_ERROR_INVALID_SYNTAX_WITHOPT, 0 )
  63. #define ERROR_BADKEYNAME GetResString2( IDS_ERROR_BADKEYNAME, 0 )
  64. #define ERROR_NONREMOTABLEROOT GetResString2( IDS_ERROR_NONREMOTABLEROOT, 0 )
  65. #define ERROR_NONLOADABLEROOT GetResString2( IDS_ERROR_NONLOADABLEROOT, 0 )
  66. #define ERROR_PATHNOTFOUND GetResString2( IDS_ERROR_PATHNOTFOUND, 0 )
  67. #define ERROR_DELETEPARTIAL GetResString2( IDS_ERROR_PARTIAL_DELETE, 0 )
  68. #define ERROR_COPYTOSELF_COPY GetResString2( IDS_ERROR_COPYTOSELF_COPY, 0 )
  69. #define ERROR_COMPARESELF_COMPARE GetResString2( IDS_ERROR_COMPARESELF_COMPARE, 0 )
  70. #define KEYS_IDENTICAL_COMPARE GetResString2( IDS_KEYS_IDENTICAL_COMPARE, 0 )
  71. #define KEYS_DIFFERENT_COMPARE GetResString2( IDS_KEYS_DIFFERENT_COMPARE, 0 )
  72. #define ERROR_READFAIL_QUERY GetResString2( IDS_ERROR_READFAIL_QUERY, 0 )
  73. #define STATISTICS_QUERY GetResString2( IDS_STATISTICS_QUERY, 0 )
  74. #define ERROR_NONREMOTABLEROOT_EXPORT GetResString2( IDS_ERROR_NONREMOTABLEROOT_EXPORT, 0 )
  75. //
  76. // NOTE: do not change the order of the below listed enums -- if you change
  77. // the order, change the order in ParseRegCmdLine also
  78. enum
  79. {
  80. REG_QUERY = 0,
  81. REG_ADD = 1,
  82. REG_DELETE = 2, REG_COPY = 3,
  83. REG_SAVE = 4, REG_RESTORE = 5,
  84. REG_LOAD = 6, REG_UNLOAD = 7,
  85. REG_COMPARE = 8,
  86. REG_EXPORT = 9, REG_IMPORT = 10,
  87. REG_OPTIONS_COUNT
  88. };
  89. enum
  90. {
  91. REG_FIND_ALL = 0x7, // 0000 0000 0000 0111
  92. REG_FIND_KEYS = 0x1, // 0000 0000 0000 0001
  93. REG_FIND_VALUENAMES = 0x2, // 0000 0000 0000 0010
  94. REG_FIND_DATA = 0x4 // 0000 0000 0000 0100
  95. };
  96. //
  97. // global constants
  98. extern const WCHAR g_wszOptions[ REG_OPTIONS_COUNT ][ 10 ];
  99. //
  100. // global data structure
  101. //
  102. typedef struct __tagRegParams
  103. {
  104. LONG lOperation; // main operation being performed
  105. HKEY hRootKey;
  106. BOOL bUseRemoteMachine;
  107. BOOL bCleanRemoteRootKey;
  108. BOOL bForce; // /f -- forceful overwrite / delete
  109. BOOL bAllValues; // /va
  110. BOOL bRecurseSubKeys; // /s -- recurse
  111. BOOL bCaseSensitive; // /c
  112. BOOL bExactMatch; // /e
  113. BOOL bShowTypeNumber; // /z
  114. DWORD dwOutputType; // /oa, /od, /on
  115. LONG lRegDataType; // reg value data type (/t)
  116. WCHAR wszSeparator[ 3 ]; // separator (used for REG_MULTI_SZ)
  117. LPWSTR pwszMachineName; // machine name (in UNC format)
  118. LPWSTR pwszSubKey; // registry sub key -- excluding hive
  119. LPWSTR pwszFullKey; // full key -- including hive
  120. LPWSTR pwszValueName; // /v or /ve
  121. LPWSTR pwszValue; // /d
  122. DWORD dwSearchFlags; // /k, /v, /d
  123. LPWSTR pwszSearchData; // /f
  124. TARRAY arrTypes; // /t (REG QUERY only)
  125. } TREG_PARAMS, *PTREG_PARAMS;
  126. //
  127. // helper struture -- used to output the registry data
  128. //
  129. #define RSI_IGNOREVALUENAME 0x00000001
  130. #define RSI_IGNORETYPE 0x00000002
  131. #define RSI_IGNOREVALUE 0x00000004
  132. #define RSI_IGNOREMASK 0x0000000F
  133. #define RSI_ALIGNVALUENAME 0x00000010
  134. #define RSI_SHOWTYPENUMBER 0x00000020
  135. typedef struct __tagRegShowInfo
  136. {
  137. DWORD dwType;
  138. DWORD dwSize;
  139. LPBYTE pByteData;
  140. LPCWSTR pwszValueName;
  141. DWORD dwMaxValueNameLength;
  142. DWORD dwFlags;
  143. DWORD dwPadLength; // default is no padding
  144. LPCWSTR pwszSeparator; // default is space
  145. LPCWSTR pwszMultiSzSeparator; // default is '\0'
  146. } TREG_SHOW_INFO, *PTREG_SHOW_INFO;
  147. // helper functions
  148. LONG IsRegDataType( LPCWSTR pwszStr );
  149. BOOL SaveErrorMessage( LONG lLastError );
  150. BOOL FreeGlobalData( PTREG_PARAMS pParams );
  151. BOOL InitGlobalData( LONG lOperation, PTREG_PARAMS pParams );
  152. BOOL RegConnectMachine( PTREG_PARAMS pParams );
  153. BOOL BreakDownKeyString( LPCWSTR pwszStr, PTREG_PARAMS pParams );
  154. BOOL ShowRegistryValue( PTREG_SHOW_INFO pShowInfo );
  155. LPCWSTR GetTypeStrFromType( LPWSTR pwszTypeStr, DWORD* pdwLength, DWORD dwType );
  156. LONG Prompt( LPCWSTR pwszFormat, LPCWSTR pwszValue, LPCWSTR pwszList, BOOL bForce );
  157. LPWSTR GetTemporaryFileName( LPCWSTR pwszSavedFilePath );
  158. // option implementations
  159. BOOL Usage( LONG lOperation );
  160. LONG AddRegistry( DWORD argc, LPCWSTR argv[] );
  161. LONG CopyRegistry( DWORD argc, LPCWSTR argv[] );
  162. LONG DeleteRegistry( DWORD argc, LPCWSTR argv[] );
  163. LONG SaveHive( DWORD argc, LPCWSTR argv[] );
  164. LONG RestoreHive( DWORD argc, LPCWSTR argv[] );
  165. LONG LoadHive( DWORD argc, LPCWSTR argv[] );
  166. LONG UnLoadHive( DWORD argc, LPCWSTR argv[] );
  167. LONG CompareRegistry( DWORD argc, LPCWSTR argv[] );
  168. LONG QueryRegistry( DWORD argc, LPCWSTR argv[] );
  169. LONG ImportRegistry( DWORD argc, LPCWSTR argv[] );
  170. LONG ExportRegistry( DWORD argc, LPCWSTR argv[] );
  171. #endif //_REG_H