3 out of 5 rated this helpful - Rate this topic

RegDeleteTree function

Applies to: desktop apps only

Deletes the subkeys and values of the specified key recursively.

Syntax

LONG WINAPI RegDeleteTree(
  __in      HKEY hKey,
  __in_opt  LPCTSTR lpSubKey
);

Parameters

hKey [in]

A handle to an open registry key. The key must have been opened with the following access rights: DELETE, KEY_ENUMERATE_SUB_KEYS, and KEY_QUERY_VALUE. For more information, 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, optional]

The name of the key. This key must be a subkey of the key identified by the hKey parameter. If this parameter is NULL, the subkeys and values of hKey are deleted.

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 has values, it must be opened with KEY_SET_VALUE or this function will fail with ERROR_ACCESS_DENIED.

To compile an application that uses this function, define _WIN32_WINNT as 0x0600 or later. For more information, see Using the Windows Headers.

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008

Header

Winreg.h (include Windows.h)

Library

Advapi32.lib

DLL

Advapi32.dll

Unicode and ANSI names

RegDeleteTreeW (Unicode) and RegDeleteTreeA (ANSI)

See also

RegDeleteKey
RegDeleteKeyEx
Registry Functions

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Windows XP
On Windows XP you can use SHDeleteKey instead of this function.
Function now fails if used from Windows 7 on Windows XP
This function, as well as ShDeleteKey will now fail if called from a Windows 7 client to remotely delete a key on a Windows XP computer.  Problem was reported to Microsoft, they know about it, but indicated a fix is unlikely.    The only method to delete a key on Windows XP (when executed on Windows 7) is to recursively call RegDeleteKey.