Share via


RegistryDeleteValue

Send Feedback

This function deletes a specified registry value.

HRESULT WINAPI RegistryDeleteValue( 
  HKEY hKey
  LPCTSTR pszSubKey,
  LPCTSTR pszValueName
);

Parameters

  • hKey
    Handle to a currently open key, or a predefined root value.
  • pszSubKey
    The key under which the value is stored (if this value is NULL, pszValueName is assumed to be under hKey).
  • pszValueName
    The name of the value to delete (if this parameter is NULL, the default value is deleted).

Return Values

Value Description
S_OK The value was deleted successfully.
S_FALSE The key or value does not exist.
E_INVALIDARG Invalid hKey.
An error value returned. Error value wrapped as a FACILITY_WIN32 HRESULT.

Remarks

The value under the hKey+pszSubKey will be deleted if it exists, if the value does not exist, there is no change and this method will succeed.

If the key pointed to by hKey+pszSubKey does not exist, RegistryDeleteValue will fail since it uses RegOpenKey to access the key.

Code Example

The following code example demonstrates how to use RegistryDeleteValue.

Note   To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.

void ClearRegistrySettings()
{

    HKEY hkey;

    // Clear one value from HKEY_LOCAL_MACHINE.
    RegistryDeleteValue(HKEY_LOCAL_MACHINE, 
                        TEXT("Software\\MyApplication"), 
                        TEXT("SystemValue"));

    // Re-use the HKEY_CURRENT_USER handle.
    RegOpenKeyEx(HKEY_CURRENT_USER, 
                 TEXT("Software\\MyApplication"), 
                 0, 
                 0, 
                 &hkey);

    RegistryDeleteValue(hkey, NULL, TEXT("UserValue1"));
    RegistryDeleteValue(hkey, NULL, TEXT("UserValue2"));

    // Clean up
    RegCloseKey(hkey);

}

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.