Share via


RegistrySetString

Send Feedback

This function sets the REG_SZ registry value.

HRESULT WINAPI RegistrySetString( 
  HKEY hKey,
  LPCTSTR pszSubKey,
  LPCTSTR pszValueName,
  LPCTSTR pszData 
);

Parameters

  • hKey
    [in] Handle to the open key or a predefined root value.
  • pszSubKey
    [in] Key where the value is stored. If this value is NULL, then pszValueName is assumed to be under hkey.
  • pszValueName
    [in] Named value to set. If this value is NULL, the function sets the default value.
  • pszData
    [in] New value. The string must be null terminated.

Return Values

The following table shows the return values for this function.

Value Description
S_OK Value in pszValueName is replaced by the value in pszData.
E_INVALIDARG Invalid hkey or pszData.
E_DATATYPE_MISMATCH The value is not type REG_SZ.
An error value returned by RegOpenKey or RegQueryValueEx. Error value wrapped as a FACILITY_WIN32 HRESULT.
An error value returned by StringCbLength. Error value wrapped as a FACILITY_WIN32 HRESULT.

Remarks

Success indicates that the old value is replaced by the new value. Failure does cause any change.

If the key pointed to by hkey and pszSubkey does not exist, the function fails.

If the client might be calling RegistrySetString multiple times, it should cache a handle to the key using RegOpenKeyEx and pass the handle instead of passing a string value. Every time RegistrySetString is called with a string value for the key, the RegOpenKeyEx and RegCloseKey functions are called, so passing a handle instead of a string value can avert a potential performance problem over mutltiple calls.

Requirements

Pocket PC: Windows Mobile 5.0 and later.
Smartphone: Windows Mobile 5.0 and later.
OS Versions: Windows CE 5.01 and later.
Header: Regext.h
Link Library: Aygshell.lib

See Also

State and Notifications Broker Functions | State and Notifications Broker Reference | State and Notifications Broker

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.