RegLoadKey Function

The RegLoadKey function copies the information from a specified registry key and its subkeys from a file into the specified key in the registry.

Syntax

LONG RegLoadKey(
  HKEY  hKey,
  LPCSTR lpSubKey,
  LPCSTR lpFile
);

Parameters

Parameter Description
hKey A handle to an open key in the registry. This handle cannot be HKEY_LOCAL_MACHINE or HKEY_USERS. The key identified by hKey must have been opened with the KEY_READ access right.
lpSubKey A pointer to a null-terminated string specifying the name of the subkey of hKey that will contain the loaded key. This subkey must be present. If this parameter is NULL, the key is loaded into the key identified by hKey.
lpFile A pointer to a null-terminated string specifying the name of the file containing the key to be loaded. This file must be in the standard registry file format.

Return Value

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.

Error Code Description
ERROR_SUCCESS The operation was completed successfully.
ERROR_ACCESS_DENIED The user does not have the required access to perform the operation.
ERROR_FILE_NOT_FOUND The specified file was not found.
ERROR_INVALID_PARAMETER An invalid parameter was passed to the function.

Remarks

Note: For security reasons, you should not allow users to specify the file name or the registry key name. An attacker could potentially load a malicious registry hive or overwrite critical system keys.

The RegLoadKey function is used to load a subtree from a file into a specified key. The key specified by lpSubKey must already exist. The function effectively merges the data from the specified file into the registry.

Use RegUnloadKey to unload a key loaded with RegLoadKey.

Requirements

Client Windows 2000 Professional, Windows XP, Windows Vista, Windows 7, Windows 8, Windows 10
Server Windows 2000 Server, Windows Server 2003, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server 2016
Header Winreg.h
Library Advapi32.lib
DLL Advapi32.dll