Windows applications | Microsoft Learn
LONG RegUnloadKey( HKEY hKey, LPCSTR lpSubKey );
| Parameter | Description |
|---|---|
hKey |
A handle to an open registry key. The key is assumed to have been opened with the This parameter can be a handle to a predefined registry key or a handle returned by the |
lpSubKey |
The name of the subkey of the key specified by This subkey must be a volatile key. Volatile keys are not written to disk. Calls to |
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a non-zero 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.
Possible return values include:
ERROR_SUCCESS: The operation was successful.ERROR_CANNOT_DELETE: Windows cannot delete some of the keys or entries.ERROR_INVALID_HANDLE: The handle specified is not valid.ERROR_SUCCESS_REBOOT_REQUIRED: The operation requires a reboot.The RegUnloadKey function unloads a previously loaded key and its subkeys. The key must be volatile.
For a key to be unloadable, it must have been loaded by RegLoadKey.
The handle hKey must be a handle to an open key that is a parent of the key to be unloaded. For example, to unload the "MyCompany" subkey, which is a subkey of HKEY_LOCAL_MACHINE\Software, you would open HKEY_LOCAL_MACHINE\Software and pass the handle to this key, along with the subkey name "MyCompany".
RegUnloadKey is the inverse of RegLoadKey.
The current user must have administrative privileges to unload a key.
This function does not affect the registry hive on disk. The data is only removed from memory.
The RegUnloadKey function is not recommended for general use. It is intended for use by system components that need to unload registry hives. For most applications, it is sufficient to close the handle to the key using RegCloseKey.
winreg.h (include Windows.h)
Advapi32.lib
Advapi32.dll