xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

SetRegistry()

Creates a key/value pair in the registry.

Syntax

SetRegistry( <nHKEY>   , ;
             <cRegPath>, ;
             <cRegKey> , ;
             <xValue>    ) --> lSuccess

Arguments

<nHKEY>
This numeric parameter specifies the root entry in the Windows registry to create a new registry key in. #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 registry path to create <cRegKey> in. 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 create. It is created directly underneath <cRegPath>.
<xValue>
This is a value of data type Character, Date, Logical or Numeric to assign to <cRegKey>.

Return

The function returns .T. (true), when the specified key/value pair is created in the registry. Otherwise .F. (false) is returned.

Description

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 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 change the registry.

Info

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

Example

// 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

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