Platform SDK: Registry

RegLoadKey

The RegLoadKey function creates a subkey under HKEY_USERS or HKEY_LOCAL_MACHINE and stores registration information from a specified file into that subkey. This registration information is in the form of a hive. A hive is a discrete body of keys, subkeys, and values that is rooted at the top of the registry hierarchy. A hive is backed by a single file and .LOG file.

LONG RegLoadKey(
  HKEY hKey,        // handle to open key
  LPCTSTR lpSubKey, // subkey name
  LPCTSTR lpFile    // registry file name
);

Parameters

hKey
[in] Specifies the key where the subkey will be created. This can be a predefined reserved handle value, or a handle returned by a call to RegConnectRegistry. The predefined reserved handle values are:

HKEY_LOCAL_MACHINE
HKEY_USERS

This function always loads information at the top of the registry hierarchy. The HKEY_CLASSES_ROOT and HKEY_CURRENT_USER handle values cannot be specified for this parameter, because they represent subsets of the HKEY_LOCAL_MACHINE and HKEY_USERS handle values, respectively.

lpSubKey
[in] Pointer to a null-terminated string that specifies the name of the key to be created under hKey. This subkey is where the registration information from the file will be loaded.
lpFile
[in] Pointer to a null-terminated string containing the name of a file that has registry information. This file must have been created with the RegSaveKey function. If this file does not exist, a file is created with the specified name.

Windows 95: RegLoadKey does not support long file names. If the desired file has a long file name, use the short file name to load it.

Return Values

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 hKey is a handle returned by RegConnectRegistry, then the path specified in lpFile is relative to the remote computer.

Windows NT/2000: The calling process must have the SE_RESTORE_NAME privilege. For more information about privileges, see Privileges.

Windows 95/98: No registry subkey or value name may exceed 255 characters.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winreg.h; include Windows.h.
  Library: Use Advapi32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

Registry Overview, Registry Functions, RegConnectRegistry, RegDeleteKey, RegReplaceKey, RegRestoreKey, RegSaveKey, RegUnloadKey