|Navigation: Language Reference > 13 - Built-in Functions >====== PUTREG (write value to Windows registry) ======|
PUTREG(root, keyname, valuename [,value] [,valuetype] )
|PUTREG||Writes a string value into the system registry.|
|root||A LONG integer constant, variable or expression that specifies the root section of the registry to which to write the value. Valid values for this are defined in equates.clw and are as follows:|
|keyname||A STRING constant, variable or expression that contains the key name of the key whose value is to be written. This may contain a path separated by backslash '\' characters. The keyname cannot contain a leading backslash.|
|valuename||A STRING constant, variable or expression that contains the name of the value to be written.|
|value||A STRING constant, variable or expression that contains the value to be written to the registry in the position given. If omitted, an empty string is written to the registry.|
|valuetype||A LONG integer constant, variable or expression that specifies the how to store passed value. If omitted, the default value is REG_SZ (see below).|
|Supported types (expressed as EQUATES):|
|REG_NONE||value is ignored|
|REG_SZ||value is stored as a null terminated UNICODE string (default)|
|REG_EXPAND_SZ||value is stored as a null terminated UNICODE string that can contain unexpanded environment variables.|
|REG_MULTI_SZ||value is stored as an array of null terminated UNICODE strings. Strings in the array (i.e. in value parameter) are separated with '<;0>' characters. GETREG appends 2 '<;0>' characters at the end of array if they are not given.|
|REG_DWORD||value is stored as a 32 bit number, lower bytes stored first, e.g. value equal to 12345678h is stored as '<;78h,56h,34h,12h>'|
|REG_DWORD_LITTLE_ENDIAN||the same as REG_DWORD|
|REG_DWORD_BIG_ENDIAN||value is stored as a 32 bit number with backward order of bytes, e.g. value equal to 12345678h is stored as '<;12h,34h,56h,78h>'|
|REG_QWORD||value is a 64 bit number, lower bytes are stored first|
|REG_QWORD_LITTLE_ENDIAN||the same as REG_QWORD|
|REG_BINARY||value string is a binary data of any form|
The PUTREG procedure places the value into a valuename that exists in the Windows registry. The key and value will be created if it does not exist. If the write to the registry is successful, PUTREG returns 0. If the write to the registry is unsuccessful, the result is a non-zero value.
Vista and Clarion Built-in Registry Functions
On Vista, a (non-elevated) app can READ the registry key HKLM (local machine) with no problems, but as far as writing to the Registry it needs to use HKCU (current user).
If you code sign your executable and run with elevated priveleges then you can write to HKLM
Return Data Type: LONG
!Set the root directory of Clarion 6 install
CurrentPath = 'C:\Clarion7'
MESSAGE('Unable to set the root directory') !post error if non-zero value returned
!writes the current user's color scheme to the registry
ColorScheme = 'Windows Standard'
IF PUTREG(REG_CURRENT_USER,'Control Panel\Current','Color Schemes',ColorScheme)
MESSAGE('Unable to set the color scheme') !post error if non-zero value returned