OpenKey - cRegistry
Opens a Registry Key for access
Type: Function
Return Data Type: Boolean
Parameters
| Parameter | Type | Description |
|---|---|---|
| sKeyName | String | The name of the Key to open. |
Syntax
Function OpenKey String sKeyName Returns Boolean
Call Example
Get OpenKey sKeyName to BooleanVariable
Description
The Key is opened with the security access specified by the pfAccessRights property. The phRootKey property determines the root branch of the Registry that will be used.
The Key needs to exist before it can be opened. You can check to see if the Key exists by using the KeyExists function.
| Col 1 | Col 2 |
|---|---|
| Note: | If the Key is successfully opened, the phCurrentKey property is set to the handle provided by Windows. You can use this property if you need to make low-level calls to the Windows API. |
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
Return Value
OpenKey returns True if the key is successfully opened. OpenKey returns False if the Key could not be opened.