Sets the data for the default or unnamed value of a specified registry key. The data must be a text string.
Note This function is provided only for compatibility with 16-bit versions of Windows. Applications should use the
RegSetValueEx function.
Syntax
LONG WINAPI RegSetValue(
__in HKEY hKey,
__in_opt LPCTSTR lpSubKey,
__in DWORD dwType,
__in_opt LPCTSTR lpData,
__in DWORD cbData
);
Parameters
- hKey [in]
-
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 [in, optional]
-
The name of a subkey of the hKey parameter. The function sets the default value of the specified subkey.
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.
- dwType [in]
-
The type of information to be stored. This parameter must be the REG_SZ type. To store other data types, use the
RegSetValueEx function.
- lpData [in, optional]
-
The data to be stored.
- cbData [in]
-
The size of the string pointed to by the lpData parameter, not including the terminating null character, in bytes.
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.
Requirements
| Minimum supported client | Windows 2000 Professional |
| Minimum supported server | Windows 2000 Server |
| Header | Winreg.h (include Windows.h) |
| Library | Advapi32.lib |
| DLL | Advapi32.dll |
| Unicode and ANSI names | RegSetValueW (Unicode) and RegSetValueA (ANSI) |
See Also
- RegCreateKeyEx
- RegFlushKey
- Registry Functions
- Registry Overview
- RegOpenKeyEx
- RegQueryValueEx
- RegSetValueEx
Send comments about this topic to Microsoft
Build date: 5/14/2009