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.

176 lines
6.2 KiB

  1. #ifndef __REGKEY__H__
  2. #define __REGKEY__H__
  3. #include "cstr.h"
  4. #define PACKAGE_NOT_FOUND HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)
  5. namespace AMC
  6. {
  7. //____________________________________________________________________________
  8. //
  9. // Class: CRegKey
  10. //
  11. // Purpose: A wrapper around the RegXXX APIs. Most of the RegXXX APIs
  12. // have been wrapped in this class.
  13. //
  14. // The RegXXX APIs NOT wrapped in this class are:
  15. // RegLoadKey()
  16. // RegNotifyChangeKeyValue()
  17. // RegReplaceKey()
  18. // RegUnLoadKey()
  19. //
  20. // History: 5/22/1996 RaviR Created
  21. //
  22. // Notes: This class uses C++ exception handling mechanism to throw
  23. // most of the errors returned by the RegXXX APIs. It can throw
  24. // CMemoryException
  25. // COleException
  26. //
  27. // Method RegXXX API Comment
  28. // ----------- ---------------- -------------------------
  29. //
  30. // CreateKeyEx RegCreateKeyEx By default creates a non
  31. // volatile key, with all access
  32. //
  33. // OpenKeyEx RegOpenKeyEx By default opens key with all access.
  34. // Returns FALSE if specified key not
  35. // present.
  36. //
  37. // ConnectRegistry RegConnectRegistry By default connects to the given
  38. // computer's HKEY_LOCAL_MACHINE.
  39. //
  40. // CloseKey RegCloseKey -
  41. //
  42. // DeleteKey - Delete all the keys and subkeys,
  43. // using RegDeleteKey.
  44. //
  45. // SetValueEx RegSetValueEx Sets any type of data.
  46. // SetString - Sets string type data.
  47. // SetDword - Sets DWORD type data.
  48. //
  49. // QueryValueEx RegQueryValueEx Query's for any type of data.
  50. // QueryString - Query's for string type data.
  51. // QueryDword - Query's for DWORD type data.
  52. //
  53. // EnumKeyEx RegEnumKeyEx Returns FALSE if no more items present.
  54. //
  55. // EnumValue RegEnumValue Returns ERROR_NO_MORE_ITEMS if no more
  56. // values present, or ERROR_MORE_DATA if
  57. // provided buffer is insufficient.
  58. //
  59. // GetKeySecurity RegGetKeySecurity Returns FALSE on insufficent buffer.
  60. //
  61. // SetKeySecurity RegSetKeySecurity -
  62. //
  63. // SaveKey RegSaveKey -
  64. //
  65. // RestoreKey RegRestoreKey -
  66. //
  67. //____________________________________________________________________________
  68. //
  69. class CRegKey
  70. {
  71. public:
  72. // Constructor & Destructor
  73. CRegKey(HKEY hKey = NULL);
  74. ~CRegKey(void);
  75. BOOL IsNull() { return (m_hKey == NULL); }
  76. // Attributes
  77. operator HKEY() { ASSERT(m_hKey); return m_hKey; }
  78. LONG GetLastError() { return m_lastError; }
  79. // Operations
  80. // Attach/Detach
  81. HKEY AttachKey(HKEY hKey);
  82. HKEY DetachKey(void) { return AttachKey(NULL); }
  83. // Open & Create Operations
  84. void CreateKeyEx(
  85. HKEY hKeyAncestor,
  86. LPCTSTR lpszKeyName,
  87. REGSAM security = KEY_ALL_ACCESS,
  88. DWORD * pdwDisposition = NULL,
  89. DWORD dwOption = REG_OPTION_NON_VOLATILE,
  90. LPSECURITY_ATTRIBUTES pSecurityAttributes = NULL);
  91. BOOL OpenKeyEx(
  92. HKEY hKey,
  93. LPCTSTR lpszKeyName = NULL,
  94. REGSAM security = KEY_ALL_ACCESS);
  95. // Connect to another machine
  96. void ConnectRegistry(LPTSTR pszComputerName,
  97. HKEY hKey = HKEY_LOCAL_MACHINE);
  98. // Close & Delete Operations
  99. void CloseKey(void);
  100. void DeleteKey(LPCTSTR lpszKeyName);
  101. void DeleteValue(LPCTSTR lpszValueName);
  102. // Flush operation
  103. void FlushKey();
  104. // Main Access Operations
  105. void SetValueEx(LPCTSTR lpszValueName, DWORD dwType,
  106. const void * pData, DWORD nLen);
  107. void QueryValueEx(LPCTSTR lpszValueName, LPDWORD pType,
  108. PVOID pData, LPDWORD pLen);
  109. BOOL IsValuePresent(LPCTSTR lpszValueName);
  110. // Additional string access Operations
  111. void SetString(LPCTSTR lpszValueName, LPCTSTR lpszString);
  112. void SetString(LPCTSTR lpszValueName, CStr& str);
  113. BOOL QueryString(LPCTSTR lpszValueName, LPTSTR pBuffer,
  114. DWORD *pdwBufferByteLen, DWORD *pdwType = NULL);
  115. void QueryString(LPCTSTR lpszValueName, LPTSTR * ppStrValue,
  116. DWORD * pdwType = NULL);
  117. void QueryString(LPCTSTR lpszValueName, CStr& str,
  118. DWORD * pdwType = NULL);
  119. // Additional DWORD access Operations
  120. void SetDword(LPCTSTR lpszValueName, DWORD dwData);
  121. void QueryDword(LPCTSTR lpszValueName, LPDWORD pdwData);
  122. // Additional GUID access Operations
  123. void SetGUID(LPCTSTR lpszValueName, const GUID& guid);
  124. void QueryGUID(LPCTSTR lpszValueName, GUID* pguid);
  125. // Iteration Operations
  126. BOOL EnumKeyEx(DWORD iSubkey, LPTSTR lpszName, LPDWORD lpcchName,
  127. PFILETIME lpszLastModified = NULL);
  128. HRESULT EnumValue(DWORD iValue, LPTSTR lpszValue, LPDWORD lpcchValue,
  129. LPDWORD lpdwType = NULL, LPBYTE lpbData = NULL,
  130. LPDWORD lpcbData = NULL);
  131. // Key Security access
  132. BOOL GetKeySecurity(SECURITY_INFORMATION SecInf,
  133. PSECURITY_DESCRIPTOR pSecDesc, LPDWORD lpcbSecDesc);
  134. void SetKeySecurity(SECURITY_INFORMATION SecInf,
  135. PSECURITY_DESCRIPTOR pSecDesc);
  136. // Save/Restore to/from a file
  137. void SaveKey(LPCTSTR lpszFile, LPSECURITY_ATTRIBUTES lpsa = NULL);
  138. void RestoreKey(LPCTSTR lpszFile, DWORD fdw = 0);
  139. protected:
  140. // Data
  141. HKEY m_hKey;
  142. LONG m_lastError; // error code from last function call
  143. // implementation helpers
  144. static LONG NTRegDeleteKey(HKEY hStartKey, LPCTSTR pKeyName);
  145. }; // class CRegKey
  146. } // AMC namespace
  147. #endif // __REGKEY__H__