cObject
---cRegistry
The Registry is a database that an application can use to store information. The Registry stores information in a hierarchical tree, with each node of the tree referred to as a Key. Each Key can contain other Keys, referred to as Subkeys, and application data. The data is contained in Values.
All Keys that an application creates, opens, reads, or writes are Subkeys of predefined root Keys. By default, a cRegistry object is created with a root key of HKEY_CURRENT_USER.
A Key can contain an unlimited number of Subkeys and Values.
To access Values or Subkeys, you must first open or create a Key. When you have finished accessing the Subkeys or Values, you must close the Key.
Each object of cRegistry can only access one Key at a time. Therefore, you must close the current Key before opening another Key.
To create a Key, use CreateKey; to open a Key, use OpenKey; and to delete a Key, use the DeleteKey method. To determine the root branch of the Registry that these methods operate on, use the phRootKey property. You can discover how many Subkeys there are of a Key with the CountOfSubkeys method, and you can enumerate them using the GetSubkeys method. To determine whether a Key exists, use the KeyExists method.
You can write Values to the open Key using WriteBinary, WriteInteger, WriteString and WriteUInt. You can read the Values back using ReadBinary, ReadInteger, ReadString and ReadUInt. You can discover how many Values there are with CountOfValues and you can enumerate them with GetValues. To determine whether a Value already exists, use ValueExists . To determine the datatype of a Value, use the ValueType method. You can delete a Value with DeleteValue.
When you have finished accessing a Key, you should close it with CloseKey. For performance, Windows can delay committing your changes, but you can force Windows to commit the changes when you close the Key by setting the pbLazyWrite property to False.
When you open or create a Key, you can determine the type of access that you want. So, for example, if you only want to read a Key, you can set the access to read-only. This can be necessary when you are accessing Keys that will not grant you write privileges. To change the access privileges, use the pfAccessRights property.
When a Key is opened, the phCurrentKey property is set to the handle that Windows refers to the Key by. Generally, you will not use this property. However, as the cRegistry is a wrapper to the Windows Registry, you can use this handle to communicate with the Windows API.
Each Key has a special Value, called the "Default Value". This Key does not have a name; to access it, you will need to provide a null string as the Value name in any function that requires the name of a Value.
All access to the Registry, including reading of values, requires that the appropriate access rights to the Registry keys or values in questions are set prior to performing any actions. Prior versions of Windows did not enforce this rule. To change the access privileges, use the pfAccessRights property.
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.
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 oRegistrySee Also