6 out of 10 rated this helpful Rate this topic

RegDeleteKey function

Deletes a subkey and its values. Note that key names are not case sensitive.

64-bit Windows:  On WOW64, 32-bit applications view a registry tree that is separate from the registry tree that 64-bit applications view. To enable an application to delete an entry in the alternate registry view, use the RegDeleteKeyEx function.

Syntax

LONG WINAPI RegDeleteKey(
  __in  HKEY hKey,
  __in  LPCTSTR lpSubKey
);

Parameters

hKey [in]

A handle to an open registry key. The access rights of this key do not affect the delete operation. For more information about access rights, see Registry Key Security and Access Rights.

This handle is returned by the RegCreateKeyEx or RegOpenKeyEx function, or it can be one of the following Predefined Keys:

HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
lpSubKey [in]

The name of the key to be deleted. It must be a subkey of the key that hKey identifies, but it cannot have subkeys. This parameter cannot be NULL.

The function opens the subkey with the DELETE access right.

Key names are not case sensitive.

For more information, see Registry Element Size Limits.

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. To get a generic description of the error, you can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag.

Remarks

A deleted key is not removed until the last handle to it is closed.

The subkey to be deleted must not have subkeys. To delete a key and all its subkeys, you need to enumerate the subkeys and delete them individually. To delete keys recursively, use the RegDeleteTree or SHDeleteKey function.

Examples

For an example that uses this function, see Deleting a Key with Subkeys.

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

RegDeleteKeyW (Unicode) and RegDeleteKeyA (ANSI)

See also

RegCloseKey
RegCreateKeyEx
RegDeleteTree
Registry Functions
Registry Overview
RegOpenKeyEx
SHDeleteEmptyKey
SHDeleteKey

 

 

Send comments about this topic to Microsoft

Build date: 9/7/2011

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Bug in Windows Vista
This function may return ERROR_NO_ACCESS which is a bug in at least Windows Vista:

When lpSubKey points to a location within a memory that has been allocated via GlobalAlloc(GMEM_FIXED...) you get this error.
The solution is to copy the String to a local buffer on the stack.