Skip to content

Reg_Open_Key

Obsolete

This command is obsolete. Use the cRegistry class for accessing the Windows Registry in DataFlex.

Purpose

To open a registry key named sNewKeyName, where sNewKeyName is a pathname of a registry key.

Syntax

Reg_Open_Key
    sNewKeyName
To
    hKey

What It Does

Reg_Open_Key opens a registry key with the current registry root tree. Registry keys are the principal means of storing application and system configuration information in Windows. You may access the contents of a registry key by using Get_Profile_String or Get_Profile_Dword.

sNewKeyName must be a fully qualified key name, not including the root node name.

For example, the fully qualified path name to the VDF7 root is:

Software\Data Access Corporation\DataFlex\7

hKey will return as Zero if the key cannot be accessed. This may be because you do not have appropriate rights to the key or because the key does not exist. Invoke the Win32 API function GetLastError to get the error code.

Example

Procedure OnClick
End_Procedure

Object oCurrentConfigRegistry Is A Array
    Function OpenCurrentConfigKey String sKey Returns Integer
        Handle hKey
        Handle hRegRoot
        String sDefaultPath

        // Create a key within the HKEY_CURRENT_CONFIG tree.
        // Save off current root settings for later restore.
        Get_Registry_Root To hRegRoot sDefaultPath
        Set_Registry_Root To HKey_Current_Config ""
        Reg_Open_Key sKey To hKey
        Set_Registry_Root to hRegRoot sDefaultPath

        Function_Return hKey
    End_Function

    Procedure Test
        Handle hRegKey
        Move (OpenCurrentConfigKey(current_object, "System\CurrentControlSet\Control\Print\Printers")) To hRegKey

        if (hRegKey <> 0) Begin
            Showln "Opened key " hRegKey
            Reg_Close_Key hRegKey
        End
        Else 
            Showln "Reg_Open_Key failed!"
    End_Procedure
End_Object

Notes

  • Reg_Open_Key requires KEY_READ rights.
  • The key is opened in the current registry root tree. To change the registry root node, use SET_REGISTRY_ROOT. The default value is HKEY_LOCAL_MACHINE.
  • Do not forget to close the key using the Reg_Close_Key command.