Reg32() fails under Vista

Post Reply
User avatar
Badara Thiam
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France
Contact:

Reg32() fails under Vista

Post by Badara Thiam »

Antonio,

I have solve a problem with Reg32() class under Vista.
Access to registry is sometimes not possible because
of access rights. To solve it if you want just read in registry,
you must update Reg32():New() with something like that :

Code: Select all

// Registry Specific Access Rights.

#define KEY_QUERY_VALUE         1    // 0x0001
#define KEY_SET_VALUE           2    // 0x0002
#define KEY_CREATE_SUB_KEY      4    // 0x0004
#define KEY_ENUMERATE_SUB_KEYS  8    // 0x0008
#define KEY_NOTIFY              16   // 0x0010
#define KEY_CREATE_LINK         32   // 0x0020


//----------------------------------------------------------------------------//

CLASS TReg32

   DATA   cRegKey, nKey, nHandle, nError, lError

   METHOD New( nKey, cRegKey, lShowError, nRegistrySpecificAccessRights ) CONSTRUCTOR

   METHOD Create( nKey, cRegKey ) CONSTRUCTOR

   METHOD Get( cSubKey, uVar )

   METHOD Set( cSubKey, uVar )

   METHOD Close() INLINE If(::lError,,RegCloseKey( ::nHandle ))

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( nKey, cRegKey, lShowError, nRegistrySpecificAccessRights ) CLASS TReg32

   local nReturn, nHandle := 0

   DEFAULT cRegKey  := ""
   DEFAULT ::lError := .f.

   #ifdef __XPP__
      #undef New
   #endif

   #ifdef __XPP__
      do case
         case nKey == HKEY_CLASSES_ROOT
              nKey = 1

         case nKey == HKEY_CURRENT_USER
              nKey = 2

         case nKey == HKEY_LOCAL_MACHINE
              nKey = 3

         case nKey == HKEY_USERS
              nKey = 4

         case nKey == HKEY_PERFORMANCE_DATA
              nKey = 5

         case nKey == HKEY_CURRENT_CONFIG
              nKey = 6

         case nKey == HKEY_DYN_DATA
              nKey = 7
      endcase
   #endif

   #ifdef __CLIPPER__
      ::nError = RegOpenKeyEx( nKey, cRegKey,, IIF(nRegistrySpecificAccessRights = NIL, KEY_ALL_ACCESS, nRegistrySpecificAccessRights), @nHandle )
   #else
      ::nError = RegOpenKeyExA( nKey, cRegKey,, IIF(nRegistrySpecificAccessRights = NIL, KEY_ALL_ACCESS, nRegistrySpecificAccessRights), @nHandle )
   #endif

*   IF ISCLIPPER()
*      ::nError = RegOpenKeyEx( nKey, cRegKey,, KEY_ALL_ACCESS, @nHandle )
*   ELSE
*      ::nError = RegOpenKeyExA( nKey, cRegKey,, KEY_ALL_ACCESS, @nHandle )
*   ENDIF


   ::cRegKey = cRegKey
   ::nHandle = nHandle

return Self

//----------------------------------------------------------------------------//
Actualy when i use Reg32() class, it is only to read into.
I think it would be better to give the default
to KEY_QUERY_VALUE instead KEY_ALL_ACCESS.
On Vista this i very nice for me.

Regards,
Badara Thiam
http://www.icim.fr
User avatar
JC
Posts: 445
Joined: Thu Feb 21, 2008 11:58 am
Location: Brazil
Contact:

Post by JC »

Badara,

Take a look... A little correction for defines at XP and Vista!
Works very fine! Under both... including 98, ME and 2000 and above!

Code: Select all

#IFNDEF __XPP__

   # Define  HKEY_CLASSES_ROOT       2147483648
   # Define  HKEY_CURRENT_USER       2147483649
   # Define  HKEY_LOCAL_MACHINE      2147483650
   # Define  HKEY_USERS              2147483651
   # Define  HKEY_PERFORMANCE_DATA   2147483652
   # Define  HKEY_CURRENT_CONFIG     2147483653
   # Define  HKEY_DYN_DATA           2147483654

#ELSE

   # Define  HKEY_CLASSES_ROOT       1
   # Define  HKEY_CURRENT_USER       2
   # Define  HKEY_LOCAL_MACHINE      3
   # Define  HKEY_USERS              4
   # Define  HKEY_PERFORMANCE_DATA   5
   # Define  HKEY_CURRENT_CONFIG     6
   # Define  HKEY_DYN_DATA           7

#ENDIF

For using with:
regOpenKey( HKEY_LOCAL_MACHINE, "key", @nHandle )
or
TReg32():create( HKEY_LOCAL_MACHINE, "key" )
Peace and lighting!

Júlio César M. Ferreira

FWH 8.10 / xHB 1.1.0 / xDevStudio 0.72 / Pelles C 5.0.1 / SQLLIB 1.9
Post Reply