| xHarbour Reference Documentation > Function Reference | 
![]()  | 
  ![]()  | 
  ![]()  | 
 
Creates a key/value pair in the registry.
SetRegistry( <nHKEY>   , ;
             <cRegPath>, ;
             <cRegKey> , ;
             <xValue>    ) --> lSuccess
The function returns .T. (true), when the specified key/value pair is created in the registry. Otherwise .F. (false) is returned.
Function SetRegistry() creates a key/value pair in the Windows registry. If the key <cRegKey> exists already, the value <xValue> is assigned. The value may only be of Valtype() "C", "D", "L" or "N". Other data types are not supported.
A Date value is converted with function StoD() an stored as a REG_SZ value in the registry
A logical value will be converted to 1 or 0 and set as REG_DWORD.
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. SetRegistry() 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 change the registry.
| See also: | QueryRegistry(), GetRegistry() | 
| Category: | Registry functions , xHarbour extensions | 
| Header: | Winreg.ch | 
| Source: | rtl\winreg.prg | 
| LIB: | xhb.lib | 
| DLL: | xhbdll.dll | 
// The example creates a new registry path and fills it with
// five new key/value pairs. The new created keys are read from
// the registry and displayed.
   * #include "Winreg.ch"           // not needed for this example
   #define HKEY_CURRENT_USER  0     // use alternative #define constant
   PROCEDURE Main
      LOCAL nHKey    := HKEY_CURRENT_USER
      LOCAL cRegPath := "SOFTWARE\MyApplication"
      LOCAL hRegKey  := Hash()
      LOCAL cRegKey
      hRegKey["Version"]      := "1.0"
      hRegKey["Creationdate"] := Date()
      hRegKey["Demo"]         := .T.
      hRegKey["Trialdays"]    := 30
      hRegKey["rootpath"]     := "C:\programs\myapp\"
      HEval( hRegKey, ;
             {|cKey, xVal| SetRegistry( nHKey, cRegPath, cKey, xVal ) ;
           } )
      FOR EACH cRegKey IN hRegKey:keys
         ? cRegKey, "=", GetRegistry( nHKey, cRegPath, cRegKey )
      NEXT
   RETURN
http://www.xHarbour.com