Source code of Windows XP (NT5)
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.

174 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. reg.hxx
  5. Abstract:
  6. contains class definition for registry access.
  7. Author:
  8. Madan Appiah (madana) 19-Dec-1994
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. Sean Woodward (t-seanwo) 26-October-1997 ADSI Update
  13. --*/
  14. #define DEFAULT_KEY_ACCESS ( KEY_QUERY_VALUE | \
  15. KEY_SET_VALUE | \
  16. KEY_CREATE_SUB_KEY | \
  17. KEY_ENUMERATE_SUB_KEYS )
  18. #define DEFAULT_CLASS L"DefaultClass"
  19. #define DEFAULT_CLASS_SIZE sizeof(DEFAULT_CLASS)
  20. #define MAX_KEY_SIZE 64 + 1
  21. #define SERVICES_KEY \
  22. L"System\\CurrentControlSet\\Services\\"
  23. typedef struct _KEY_QUERY_INFO {
  24. WCHAR Class[DEFAULT_CLASS_SIZE];
  25. DWORD ClassSize;
  26. DWORD NumSubKeys;
  27. DWORD MaxSubKeyLen;
  28. DWORD MaxClassLen;
  29. DWORD NumValues;
  30. DWORD MaxValueNameLen;
  31. DWORD MaxValueLen;
  32. DWORD SecurityDescriptorLen;
  33. FILETIME LastWriteTime;
  34. } KEY_QUERY_INFO, *LPKEY_QUERY_INFO;
  35. /*++
  36. Class Description:
  37. Defines a REGISTRY class that manipulates the registry keys.
  38. Public Member functions:
  39. Create : is a overloaded function that creates a subkey.
  40. GetValue : is a overloaded function that retrieves REG_DWORD,
  41. REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ AND REG_BINARY data values.
  42. SetValue : is a overloaded function that sets REG_DWORD,
  43. REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ AND REG_BINARY data values.
  44. GetNumSubKeys : returns number of subkeys under this key object.
  45. DeleteKey : deletes a subkey node.
  46. FindFirstKey : returns the first subkey of this key.
  47. FindNextKey : returns the next subkey of this key.
  48. --*/
  49. class REGISTRY_OBJ {
  50. private:
  51. HKEY _RegHandle;
  52. DWORD _Status;
  53. DWORD _Index;
  54. DWORD _ValIndex;
  55. DWORD GetValueSizeAndType(
  56. LPWSTR ValueName,
  57. LPDWORD ValueSize,
  58. LPDWORD ValueType );
  59. public:
  60. REGISTRY_OBJ( HKEY Handle, DWORD Error );
  61. REGISTRY_OBJ( HKEY ParentHandle, LPWSTR KeyName );
  62. REGISTRY_OBJ( REGISTRY_OBJ *ParentObj, LPWSTR KeyName );
  63. ~REGISTRY_OBJ( VOID ) {
  64. if( _RegHandle != NULL ) {
  65. RegCloseKey( _RegHandle );
  66. }
  67. return;
  68. };
  69. DWORD GetStatus( VOID ) {
  70. return( _Status );
  71. };
  72. DWORD Create( LPWSTR ChildName );
  73. DWORD Create( LPWSTR ChildName, REGISTRY_OBJ **ChildObj );
  74. DWORD Create( LPWSTR ChildName, REGISTRY_OBJ **ChildObj, DWORD *KeyDisposition );
  75. DWORD GetValue( LPWSTR ValueName, DWORD *Data );
  76. DWORD GetValue( LPWSTR ValueName, LPWSTR *Data, DWORD *NumStrings );
  77. DWORD GetValue( LPWSTR ValueName, LPBYTE *Data, DWORD *DataLen );
  78. DWORD GetValue( LPWSTR ValueName, LPBYTE Data, DWORD *DataLen );
  79. DWORD SetValue( LPWSTR ValueName, LPDWORD Data );
  80. DWORD SetValue( LPWSTR ValueName, LPWSTR Data, DWORD StringType );
  81. DWORD SetValue( LPSTR ValueName, LPSTR Data, DWORD DataLen, DWORD StringType );
  82. DWORD SetValue( LPWSTR ValueName, LPBYTE Data, DWORD DataLen );
  83. DWORD GetKeyInfo( LPKEY_QUERY_INFO QueryInfo ) {
  84. DWORD Error;
  85. QueryInfo->ClassSize = DEFAULT_CLASS_SIZE;
  86. Error = RegQueryInfoKeyW(
  87. _RegHandle,
  88. (LPWSTR)QueryInfo->Class,
  89. &QueryInfo->ClassSize,
  90. NULL,
  91. &QueryInfo->NumSubKeys,
  92. &QueryInfo->MaxSubKeyLen,
  93. &QueryInfo->MaxClassLen,
  94. &QueryInfo->NumValues,
  95. &QueryInfo->MaxValueNameLen,
  96. &QueryInfo->MaxValueLen,
  97. &QueryInfo->SecurityDescriptorLen,
  98. &QueryInfo->LastWriteTime
  99. );
  100. return( Error );
  101. }
  102. DWORD GetNumSubKeys(DWORD *NumSubKeys ) {
  103. DWORD Error;
  104. KEY_QUERY_INFO QueryInfo;
  105. Error = GetKeyInfo( &QueryInfo );
  106. if( Error == ERROR_SUCCESS ) {
  107. *NumSubKeys = QueryInfo.NumSubKeys;
  108. }
  109. return( Error );
  110. }
  111. DWORD DeleteKey( LPWSTR ChildKeyName );
  112. DWORD FindNextKey( LPWSTR Key, DWORD KeySize );
  113. DWORD FindFirstKey( LPWSTR Key, DWORD KeySize ) {
  114. _Index = 0;
  115. return( FindNextKey(Key, KeySize) );
  116. };
  117. DWORD FindNextValue( LPSTR ValueName, DWORD ValueSize,
  118. LPBYTE Data, DWORD *DataLen );
  119. DWORD FindFirstValue( LPSTR ValueName, DWORD ValueSize, LPBYTE Data,
  120. DWORD *DataLen ) {
  121. _ValIndex = 0;
  122. return( FindNextValue(ValueName, ValueSize, Data, DataLen ) );
  123. };
  124. };
  125.