Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function deletes a specified registry value.

Syntax

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, pszValueNameis assumed to be under hKey).

pszValueName

The name of the value to delete (if this parameter is NULL, the default value is deleted).

Return Value

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+ pszSubKeywill 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+ pszSubKeydoes not exist, RegistryDeleteValuewill fail since it uses RegOpenKeyto 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.
Copy Code
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.
				 0, 
				 0, 
				 &hkey);
	RegistryDeleteValue(hkey, NULL, TEXT("UserValue1"));
	RegistryDeleteValue(hkey, NULL, TEXT("UserValue2"));
	// Clean up
	RegCloseKey(hkey);
}

Requirements

Header regext.h
Library aygshell.lib
Windows Embedded CE Windows Embedded CE 6.0 and later
Windows Mobile Pocket PC for Windows Mobile Version 5.0 and later, Smartphone for Windows Mobile Version 5.0 and later

See Also