RegistrySet

Description

Sets the value for a key and value name in the system registry. If the key or value name does not exist, RegistrySet creates a new key or name and sets its value.

Syntax

RegistrySet ( key, valuename, valuetype, value )

Argument

Description

key

A string whose value names the key in the system registry whose value you want to set.

To uniquely identify a key, specify the list of parent keys above it in the hierarchy, starting with the root key. The keys in the list are separated by backslashes.

If key does not exist in the registry, RegistrySet creates a new key. To create a key without a named value, specify an empty string for valuename.

valuename

A string containing the name of a value in the registry. Each key may have several named values. To specify the unnamed value, specify an empty string.

If valuename does not exist in the registry, RegistrySet causes a new name to be created for key.

valuetype

A value of the RegistryValueType enumerated datatype identifying the datatype of a value in the registry. Values are:

  • RegString!—A null-terminated string

  • RegExpandString!—A null-terminated string that contains unexpanded references to environment variables

  • RegBinary!—Binary data

  • ReguLong!—A 32-bit number

  • ReguLongBigEndian!—A 32-bit number

  • RegLink!—A Unicode symbolic link

  • RegMultiString!—An unbounded array of strings

value

A variable corresponding to the datatype of valuetype containing a value to be set in the registry.

Returns

Integer. Returns 1 if it succeeds and -1 if an error occurs. An error is returned if the datatype of valuevariable does not correspond to the datatype specified in valuetype.

Usage

Long string values (more than 2048 bytes) should be stored as files and the file name stored in the registry.

Item

Description

Key

An element in the registry. A key is part of a tree of keys, descending from one of the predefined root keys. Each key is a subkey or child of the parent key above it in the hierarchy.

There are four root strings:

  • HKEY_CLASSES_ROOT

  • HKEY_LOCAL_MACHINE

  • HKEY_USERS

  • HKEY_CURRENT_USER

A key is uniquely identified by the list of parent keys above it. The keys in the list are separated by slashes, as shown in these examples:

HKEY_CLASSES_ROOT\Sybase.Application

HKEY_USERS\MyApp\Display\Fonts

Value name

The name of a value belonging to the key. A key can have one unnamed value and one or more named values.

Value type

A value identifying the datatype of a value in the registry.

Value

A value associated with a value name or an unnamed value. Several string, numeric, and binary datatypes are supported by the registry.

Examples

Example 1

This example sets a value for the key Fonts and the value name Title:

RegistrySet( &

 "HKEY_LOCAL_MACHINE\Software\MyApp\Fonts", &

 "Title", RegString!, sle_font.Text)

Example 2

This statement sets a value for the key Fonts and the value name NameOfEntryNum:

ulong ul_num

RegistrySet( &

 "HKEY_USERS\MyApp.Settings\Fonts", &

 "NameOfEntryNum", RegULong!, ul_num)

See also