Skip to content

KeyExists - cRegistry

Determines whether a Key exists

Type: Function
Return Data Type: Boolean

Parameters

Parameter Type Description
sKeyName String The name of the Key to check the existence of.

Syntax

Function KeyExists String sKeyName Returns Boolean

Call Example

Get KeyExists sKeyName to BooleanVariable

Description

KeyExists determines whether a Key exists before attempting to access it.

Use cRegistry.pkg

Object oRegistry is a cRegistry

    Procedure DoShowIfDacKeyExists
        Boolean bExists
        String sKey
        Handle hoRegistry

        Get Create (RefClass(cRegistry)) to hoRegistry

        // We need to change the default of phRootKey...
        Set phRootKey To HKEY_LOCAL_MACHINE
        Set pfAccessRights of hoRegistry to Key_Read

        Move "SOFTWARE\Data Access Corporation" to sKey

        Get KeyExists of hORegistry sKey to bExists
        If bExists Begin
            Send Info_Box "The Key exists (in HKEY_LOCAL_MACHINE)"
        End
        Else Begin
             Send Info_Box "No, sorry, that Key does not exist"
        End

        Send Destroy of hoRegistry
    End_Procedure

End_Object

Send DoShowIfDacKeyExists of oRegistry

Return Value

Returns True if sKeyName exists, False if the key does not exist or is "".