RegSetValueW function (winreg.h)
Sets the data for the default or unnamed value of a specified registry key. The data must be a text string.
Syntax
LSTATUS RegSetValueW(
[in] HKEY hKey,
[in, optional] LPCWSTR lpSubKey,
[in] DWORD dwType,
[in] LPCWSTR lpData,
[in] DWORD cbData
);
Parameters
[in] 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
[in, optional] lpSubKey
The name of a subkey of the hKey parameter. The function sets the default value of the specified subkey. If lpSubKey does not exist, the function creates it.
Key names are not case sensitive.
If this parameter is NULL or points to an empty string, the function sets the default value of the key identified by hKey.
For more information, see Registry Element Size Limits.
[in] dwType
The type of information to be stored. This parameter must be the REG_SZ type. To store other data types, use the RegSetValueEx function.
[in] lpData
The data to be stored. This parameter cannot be NULL.
[in] cbData
This parameter is ignored. The function calculates this value based on the size of the data in the lpData parameter.
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
If the key specified by the lpSubKey parameter does not exist, the RegSetValue function creates it.
If the ANSI version of this function is used (either by explicitly calling RegSetValueA or by not defining UNICODE before including the Windows.h file), the lpData parameter must be an ANSI character string. The string is converted to Unicode before it is stored in the registry.
Note
The winreg.h header defines RegSetValue as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | winreg.h (include Windows.h) |
Library | Advapi32.lib |
DLL | Advapi32.dll |