xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

QueryRegistry()

Checks if a particular registry key with specified value exists.

Syntax

QueryRegistry( <nHKEY>   , ;
               <cRegPath>, ;
               <cRegKey> , ;
               <xValue>  , ;
              [<lCreate>]  ) --> lExists

Arguments

<nHKEY>
This numeric parameter specifies the root entry in the Windows registry to search for a registry key. #define constants are available in the Winreg.ch file that can be used for <nHKEY>. They begin the the prefix HKEY_.
<cRegPath>
This is a character string holding the search path in the registry to locate <cRegKey>. The path must include a backslash as delimiter, if required, but may neither begin or end with a backslash.
<cRegKey>
This is a character string holding the name of the registry key to check and/or assign a value to. <cRegKey> must be located underneath <cRegPath>.
<xValue>
This is a value of data type Character, Date, Logical or Numeric to compare with the value of <cRegKey>.
<lCreate>
This parameter defaults to .F. (false), so that <cRegKey> is only searched and its value compared with <xValue>. When <lCreate> is .T. (true) a non existent key is created, and the value <xValue> is assigned to the registry key.

Return

The function returns .T. (true), when the specified registry key exists and has the value <xValue>. Otherwise .F. (false) is returned.

Description

Function QueryRegistry() checks if a registry key of a particular value exists in the registry and/or creates this key/value pair.

By default, the function searches the key/value pair beginning with the root <nHKEY>, following the search path <cRegPath>. If the key/value pair exists, the return value is .T. (true). When it does not, the return value is .F. (false), unless the optional parameter <lCreate> isset to .T. (true). In this case, a non existent key is created. The value <xValue> is assigned to an existing key.

Winreg.ch

Winreg.ch adds quite some overhead to an application program by adding structure definitions. If this is not required, Winreg.ch does not need to be #included. QueryRegistry() recognizes the following values for <nHKEY> in addition to the HKEY_* #define constants:

Registry keys
Registry KeyEquivalent value
HKEY_LOCAL_MACHINE0
HKEY_CLASSES_ROOT1
HKEY_CURRENT_USER2
HKEY_CURRENT_CONFIG3
HKEY_LOCAL_MACHINE4
HKEY_USERS5

Note:  on Windows NT, 2000, XP or later, the user may need certain security rights in order to be able to read and/or change the registry.

Info

See also:SetRegistry(), GetRegistry()
Category: Registry functions , xHarbour extensions
Header:Winreg.ch
Source:rtl\winreg.prg
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example queries the registry for entries as they exist
// after the installation of xHarbour builder of October 2006.
// One registry entry does not exist and is created.

   * #include "Winreg.ch"           // not needed for this example

   #define HKEY_CURRENT_USER  0     // use alternative #define constant

   PROCEDURE Main
      LOCAL nHKey    := 0
      LOCAL cRegPath := "SOFTWARE\xHarbour.com\xHarbour Builder"

      ? QueryRegistry( nHKey, cRegPath, "Edition", "Enterprise" )
                                    // result: .T.

      ? QueryRegistry( nHKey, cRegPath, "rootdir", "C:\xhb" )
                                    // result: .T.

      // Query non existent registry key ...
      IF .NOT. QueryRegistry( nHKey, cRegPath, ;
                             "xhb build last", "October 2006" )

         // ... and create it
         QueryRegistry( nHKey, cRegPath, ;
                       "xhb build last", "October 2006", .T. )
      ENDIF

      ? GetRegistry( nHKey, cRegPath, "xhb build last" )
                                    // result: October 2006
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe