RegSetKeyValueA function

Sets the data for the specified value in the specified registry key and subkey.

Syntax

LSTATUS RegSetKeyValueA(
  HKEY    hKey,
  LPCSTR  lpSubKey,
  LPCSTR  lpValueName,
  DWORD   dwType,
  LPCVOID lpData,
  DWORD   cbData
);

Parameters

hKey

A handle to an open registry key. The key must have been opened with the KEY_SET_VALUE access right. For more information, see Registry Key Security and Access Rights.

This handle is returned by the RegCreateKeyEx, RegCreateKeyTransacted, RegOpenKeyEx, or RegOpenKeyTransacted function. It can also be one of the following predefined keys:


   HKEY_CLASSES_ROOT
   HKEY_CURRENT_CONFIG
   HKEY_CURRENT_USER
   HKEY_LOCAL_MACHINE
   HKEY_USERS

lpSubKey

The name of a key and a subkey to the key identified by hKey. If this parameter is NULL, then this value is created in the key using the hKey value and the key gets a default security descriptor.

lpValueName

The name of the registry value whose data is to be updated.

dwType

The type of data pointed to by the lpData parameter. For a list of the possible types, see Registry Value Types.

lpData

The data to be stored with the specified value name.

For string-based types, such as REG_SZ, the string must be null-terminated. With the REG_MULTI_SZ data type, the string must be terminated with two null characters.

cbData

The size of the information pointed to by the lpData parameter, in bytes. If the data is of type REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ, cbData must include the size of the terminating null character or characters.

Return Value

If the function succeeds, the return value is ERROR_SUCCESS.

If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

Remarks

To compile an application that uses this function, define _WIN32_WINNT as 0x0600 or later. For more information, see Using the Windows Headers.

Requirements

   
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Target Platform Windows
Header winreg.h (include Windows.h)
Library Advapi32.lib
DLL Advapi32.dll

See Also

RegDeleteKeyValue

Registry Functions