Skip to content

pfAccessRights - cRegistry

Specifies the level of access when opening and creating Keys

Type: Property
Access: Read/Write
Data Type: UInteger
Parameters: None

Syntax

Property UInteger pfAccessRights
Access Type Syntax
Read Access: Get pfAccessRights to UIntegerVariable
Write Access: Set pfAccessRights to UIntegerVariable/Value

Description

Use pfAccessRights to specify the type of access to use when opening and creating Keys. As OpenKey and CreateKey use this property, it is important to set it before calling either of these functions.

The value of pfAccessRights is a set of flags that may be combined together. Each flag indicates a type of permission. Set a value that grants sufficient permission to allow the desired actions while not exceeding the anticipated access level of the system that will run the application. The following table lists the flags that can be included:

Constant Meaning
KEY_ALL_ACCESS A convenient combination of KEY_READ, KEY_WRITE, and KEY_CREATE_LINK
KEY_READ A convenient combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY
KEY_WRITE A convenient combination of KEY_SET_VALUE and KEY_CREATE_SUB_KEY
KEY_QUERY_VALUE Permission to query Subkey data
KEY_ENUMERATE_SUB_KEYS Permission to enumerate Subkeys
KEY_NOTIFY Permission for change notification
KEY_SET_VALUE Permission to set Subkey data
KEY_CREATE_SUB_KEY Permission to create Subkeys
KEY_CREATE_LINK Permission to create a symbolic link
KEY_EXECUTE Permission for read access
KEY_WOW64_32KEY Permission to access Registry keys from the 32-bit Registry view
KEY_WOW64_64KEY Permission to access Registry keys from the 64-bit Registry view

The default, KEY_ALL_ACCESS, grants full permissions to the Key. However, for operations that are completely read-only, you may want to set the property to KEY_READ, for example. Remember, it is possible that the Key, if not created by you, for example, may not grant you permission to access it to write, which is why you would set it to KEY_READ.

Operating System Permissions

Keep in mind that these access rights are restricted based on the operating system rights of the user running the application. If, for example, a user only has read rights to a specific key, setting pfAccessRights to KEY_WRITE for that key will not overwrite the user permissions set by the operating system and allow that user to write to the key.

Registry Redirection

Windows redirects Registry access for 32-bit processes to the Wow6432Node if you do not specify. By using KEY_WOW64_32KEY and KEY_WOW64_64KEY in pfAccessRights, you can override this behaviour and access the 64-bit keys from a 32-bit process and vice-versa.

  • KEY_WOW64_64KEY on a 64-bit OS means that the registry access, no matter if it's a 32 or 64 bit process, will access the 64 bit registry view.
  • KEY_WOW64_32KEY on a 64-bit OS means that the registry access, no matter if it's a 32 or 64 bit process, will access the 32 bit registry view.
  • Neither of them have any effect on a 32-bit OS.
  • Leaving the flag out (the default) on a 64-bit OS will send registry accesses from 32-bit processes to the 32 bit registry view, and accesses from 64-bit processes to the 64 bit registry view.

Example

This example shows how to access the Registry to read how many subkeys the "Data Access Worldwide" key in the HKEY_LOCAL_MACHINE branch has.

Procedure DoShowCountOfSubkeys String sKey
    Boolean bOpened bExists
    Handle hoRegistry

    Get Create (RefClass(cRegistry)) to hoRegistry

    // Set the default of phRootKey...
    Set phRootKey of hoRegistry to HKEY_LOCAL_MACHINE

    // set access rights to read
    Set pfAccessRights of hoRegistry to Key_Read

    // check if this is a 64 bit machine
    // if so, the Wow6432Node key will exist
    Get KeyExists of hoRegistry "SOFTWARE\Wow6432Node" to bExists
    If bExists Begin
        Move (Append("SOFTWARE\Wow6432Node\", sKey)) to sKey
    End
    Else Begin
        Move (Append("SOFTWARE\", sKey)) to sKey
    End

    Get KeyExists of hoRegistry sKey to bExists
    If bExists Begin
        // Open the Key...
        Get OpenKey of hoRegistry sKey to bOpened
        If bOpened Begin
            Send Info_Box (CountOfSubkeys(hoRegistry)) 'Count='
            Send CloseKey of hoRegistry
        End
    End

    Send Destroy of hoRegistry
End_Procedure

Send DoShowIfDAWKeyExists of oRegistry

See Also

OpenKey | CreateKey