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.

125 lines
4.6 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: creg.h
  6. * Content: definition of the CRegistry class
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 07/16/99 rodtoll Created
  12. * 08/18/99 rodtoll Added Register/UnRegister that can be used to
  13. * allow COM objects to register themselves.
  14. * 08/25/99 rodtoll Updated to provide read/write of binary (blob) data
  15. * 10/07/99 rodtoll Updated to work in Unicode
  16. * 10/27/99 pnewson added Open() call that takes a GUID
  17. * 01/18/00 mjn Added GetMaxKeyLen function
  18. * 01/24/00 mjn Added GetValueSize function
  19. * 04/05/2000 jtk Changed GetVauleSize to GetValueLength and modified to return WCHAR lengths
  20. * 04/21/2000 rodtoll Bug #32889 - Does not run on Win2k on non-admin account
  21. * rodtoll Bug #32952 - Does not run on Win95 GOLD w/o IE4 -- modified
  22. * to allow reads of REG_BINARY when expecting REG_DWORD
  23. * 07/09/2000 rodtoll Added signature bytes
  24. * 08/28/2000 masonb Voice Merge: Modified platform checks to use osind.cpp layer (removed CRegistry::CheckUnicodePlatform)
  25. * 04/13/2001 VanceO Moved granting registry permissions into common, and
  26. * added DeleteValue and EnumValues.
  27. * 06/19/2001 RichGr DX8.0 added special security rights for "everyone" - remove them if
  28. * they exist with new RemoveAllAccessSecurityPermissions() method.
  29. *
  30. ***************************************************************************/
  31. #ifndef __CREGISTRY_H
  32. #define __CREGISTRY_H
  33. #ifndef DPNBUILD_NOREGISTRY
  34. // Useful definition
  35. #define MAX_REGISTRY_STRING_SIZE _MAX_PATH+1
  36. #define DPN_KEY_ALL_ACCESS ((KEY_ALL_ACCESS & ~WRITE_DAC) & ~WRITE_OWNER)
  37. #define VSIG_CREGISTRY 'GERV'
  38. #define VSIG_CREGISTRY_FREE 'GER_'
  39. #define ReadBOOL( keyname, boolptr ) ReadDWORD( (keyname), (DWORD*) (boolptr) )
  40. #define WriteBOOL( keyname, boolval ) WriteDWORD( (keyname), (DWORD) (boolval) )
  41. // CRegistry
  42. //
  43. // This class handles reading/writing to the windows registry. Each instance
  44. // of the CRegistry class is attached to a single registry handle, which is
  45. // an open handle to a point in the registry tree.
  46. //
  47. class CRegistry
  48. {
  49. public:
  50. CRegistry();
  51. ~CRegistry();
  52. BOOL EnumKeys( LPWSTR lpwStrName, LPDWORD lpdwStringLen, DWORD index = 0 );
  53. BOOL EnumValues( LPWSTR lpwStrName, LPDWORD lpdwStringLen, DWORD index = 0 );
  54. BOOL Open( const HKEY branch, const LPCWSTR pathName, BOOL fReadOnly = TRUE, BOOL create = FALSE, BOOL fCustomSAM = FALSE, REGSAM samCustom = NULL);
  55. BOOL Open( const HKEY branch, const GUID* lpguid, BOOL fReadOnly = TRUE, BOOL create = FALSE, BOOL fCustomSAM = FALSE, REGSAM samCustom = NULL);
  56. BOOL Close();
  57. BOOL IsOpen() const { return m_isOpen; };
  58. BOOL DeleteSubKey( LPCWSTR keyName );
  59. BOOL DeleteSubKey( const GUID *pGuidName );
  60. BOOL DeleteValue( LPCWSTR valueName );
  61. BOOL ReadGUID( LPCWSTR keyName, GUID* guid );
  62. BOOL WriteGUID( LPCWSTR keyName, const GUID &guid );
  63. BOOL WriteString( LPCWSTR keyName, const LPCWSTR lpwstrValue );
  64. BOOL ReadString( LPCWSTR keyName, LPWSTR lpwstrValue, LPDWORD lpdwLength );
  65. BOOL WriteDWORD( LPCWSTR keyName, DWORD value );
  66. BOOL ReadDWORD( LPCWSTR keyName, DWORD* presult );
  67. BOOL ReadBlob( LPCWSTR keyName, LPBYTE lpbBuffer, LPDWORD lpdwSize );
  68. BOOL WriteBlob( LPCWSTR keyName, const BYTE* const lpbBuffer, DWORD dwSize );
  69. BOOL GetMaxKeyLen( DWORD* pdwMaxKeyLen );
  70. BOOL GetValueLength( const LPCWSTR keyName, DWORD *const pdwValueLength );
  71. #ifdef WINNT
  72. BOOL GrantAllAccessSecurityPermissions();
  73. BOOL RemoveAllAccessSecurityPermissions();
  74. #endif // WINNT
  75. #ifndef DPNBUILD_NOCOMREGISTER
  76. static BOOL Register( LPCWSTR lpszProgID, LPCWSTR lpszDesc, LPCWSTR lpszProgName, const GUID* pguidCLSID, LPCWSTR lpszVerIndProgID );
  77. static BOOL UnRegister( const GUID* pguidCLSID );
  78. #endif // !DPNBUILD_NOCOMREGISTER
  79. // Data access functions
  80. operator HKEY() const { return m_regHandle; };
  81. HKEY GetBaseHandle() const { return m_baseHandle; };
  82. HKEY GetHandle() const { return m_regHandle; };
  83. protected:
  84. DWORD m_dwSignature; // Signature
  85. BOOL m_fReadOnly;
  86. BOOL m_isOpen; // BOOL indicating if the object is open
  87. HKEY m_regHandle; // Handle to the registry which is represented by this object
  88. HKEY m_baseHandle; // Handle to the root of the part of the registry
  89. // this object is in. E.g. HKEY_LOCAL_MACHINE
  90. };
  91. #endif // ! DPNBUILD_NOREGISTRY
  92. #endif // __CREGISTRY_H