Skip to content

CloseKey - cRegistry

Closes a Registry Key

Type: Procedure

Syntax

Procedure CloseKey

Call Example

Send CloseKey

Description

The CloseKey procedure closes a Key that you have opened with either OpenKey or CreateKey.

Send the CloseKey method to commit all pending writes to the currently open Key and close it. You should not keep Keys open any longer than necessary; so close them at the earliest opportunity.

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
Col 1 Col 2
Note: Calling CloseKey when there is no Key open has no effect and does not produce an error.

See Also

pbLazyWrite | OpenKey | CreateKey