3.1.5.31 BaseRegDeleteKeyEx (Opnum 35)

The BaseRegDeleteKeyEx method is called by the client. In response, the server deletes the specified registry key.

 error_status_t BaseRegDeleteKeyEx(
   [in] RPC_HKEY hKey,
   [in] PRRP_UNICODE_STRING lpSubKey,
   [in] REGSAM AccessMask,
   [in] DWORD Reserved
 );

hKey: A handle to a key that MUST have been opened previously by using one of the open methods that are specified in section 3.1.5: OpenClassesRoot, OpenCurrentUser, OpenLocalMachine, OpenPerformanceData, OpenUsers, BaseRegCreateKey, BaseRegOpenKey, OpenCurrentConfig, OpenPerformanceText, OpenPerformanceNlsText.

lpSubKey: A pointer to an RRP_UNICODE_STRING structure that MUST specify the name of the key (as specified in section 3.1.1) to delete.

AccessMask: A bit field that describes the wanted security access for the key.

Value

Meaning

KEY_WOW64_64KEY

0x00000100

Explicitly delete the key in the 64-bit key namespace.

KEY_WOW64_32KEY

0x00000200

Explicitly delete the key in the 32-bit key namespace.

Reserved: SHOULD be sent as 0 and MUST be ignored on receipt.

Return Values: The method returns 0 (ERROR_SUCCESS) to indicate success; otherwise, it returns a nonzero error code, as specified in [MS-ERREF] section 2.2. The most common error codes are listed in the following table.

Return value/code

Description

0x00000057

ERROR_INVALID_PARAMETER

A parameter is incorrect.

0x00000013

ERROR_WRITE_PROTECT

A read or write operation was attempted to a volume after it was dismounted. The server can no longer service registry requests because server shutdown has been initiated.

Server Operations

First, if the registry server can no longer service registry requests because server shutdown has been initiated (SHUTDOWNINPROGRESS is set to TRUE), the server MUST return ERROR_WRITE_PROTECT.

If the handle provided in the hKey parameter is not a valid open handle to a registry key, the server MUST then fail the method and return ERROR_INVALID_HANDLE.

The server then determines which key namespace to operate on (KEYS32 or KEYS64) by inspecting the value of the AccessMask parameter. the server MUST first check if both the KEY_WOW64_64KEY and KEY_WOW64_32KEY bits are set in the AccessMask parameter. If both KEY_WOW64_64KEY and KEY_WOW64_32KEY are set, the server MUST fail the method and return ERROR_INVALID_PARAMETER.

The server MUST then check to see if the key specified by the hKey parameter is a key that can only be operated on in the 64-bit key namespace (KEYS64). See section 3.1.1.4.

If the key specified by the hKey parameter is a key that can only be operated on in the 64-bit key namespace (KEYS64), the server MUST ignore the KEY_WOW64_64KEY and KEY_WOW64_32KEY bits in the AccessMask parameter and operate on and delete the key in the 64-bit namespace (KEYS64).

Next, the server checks if the KEY_WOW64_32KEY is set in the AccessMask parameter. If the KEY_WOW64_32KEY is set in the AccessMask parameter, the server MUST operate on and delete the key in the 32-bit key namespace (KEYS32). If the KEY_WOW64_32KEY is not set in the AccessMask parameter, the server MUST operate on and delete the key in the 64-bit key namespace (KEYS64).

If the value of the lpSubKey parameter is NULL, the server MUST fail the method and return ERROR_INVALID_PARAMETER.

The server MUST then validate that the key indicated by lpSubKey does not have subkeys of its own. If the key indicated by lpSubKey does have child subkeys, then the server MUST fail the method and return ERROR_ACCESS_DENIED.

In response to this request from the client, for a successful operation, the server MUST delete the key specified by the lpSubKey parameter and return 0 to indicate success or an appropriate error code (as specified in [MS-ERREF]) to indicate an error.

The server MUST delete the registry key even if the subkey to be deleted is already in use and initialized in the Data Store before the deletion happens. The delete function will be successful even if other handles are open to the key. The data inside the hive is revoked at delete key time and is not deferred until the last handle close operation.