| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Checks if a particular registry key with specified value exists.
QueryRegistry( <nHKEY> , ;
<cRegPath>, ;
<cRegKey> , ;
<xValue> , ;
[<lCreate>] ) --> lExists
The function returns .T. (true), when the specified registry key exists and has the value <xValue>. Otherwise .F. (false) is returned.
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 Key | Equivalent value |
|---|---|
| HKEY_LOCAL_MACHINE | 0 |
| HKEY_CLASSES_ROOT | 1 |
| HKEY_CURRENT_USER | 2 |
| HKEY_CURRENT_CONFIG | 3 |
| HKEY_LOCAL_MACHINE | 4 |
| HKEY_USERS | 5 |
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.
| See also: | SetRegistry(), GetRegistry() |
| Category: | Registry functions , xHarbour extensions |
| Header: | Winreg.ch |
| Source: | rtl\winreg.prg |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com