Platform SDK: Registry

RegRestoreKey

The RegRestoreKey function reads the registry information in a specified file and copies it over the specified key. This registry information may be in the form of a key and multiple levels of subkeys.

LONG RegRestoreKey(
  HKEY hKey,      // handle to key where restore begins
  LPCTSTR lpFile, // registry file
  DWORD dwFlags   // options
);

Parameters

hKey
[in] Handle to a currently open key or any of the following predefined reserved handle values:

HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS

Any information contained in this key and its descendent keys is overwritten by the information in the file pointed to by the lpFile parameter.

lpFile
[in] Pointer to a null-terminated string containing the name of the file with registry information. This file is typically created by using the RegSaveKey function.
dwFlags
[in] Flag indicating how the key or keys are to be restored. This parameter can be one of the following values.
Value Meaning
REG_FORCE_RESTORE If specified, the restore operation is executed even if open handles exist at or beneath the location in the registry hierarchy the hKey parameter points to.
REG_NO_LAZY_FLUSH If specified, the key or hive specified by the hKey parameter will not be lazy flushed, or flushed automatically and regularly after an interval of time.
REG_REFRESH_HIVE If specified, the location of the hive the hKey parameter points to will be restored to its state immediately following the last flush. The hive must not be lazy flushed (by calling RegRestoreKey with REG_NO_LAZY_FLUSH specified as the value of this parameter), the caller must have TCB privilege, and the handle the hKey parameter refers to must point to the root of the hive.
REG_WHOLE_HIVE_VOLATILE If specified, a new, volatile (memory only) set of registry information, or hive, is created. If REG_WHOLE_HIVE_VOLATILE is specified, the key identified by the hKey parameter must be either the HKEY_USERS or HKEY_LOCAL_MACHINE value.

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 any subkeys of the hKey parameter are open, RegRestoreKey fails. The function also fails if the calling process does not have the SE_RESTORE_NAME privilege. For more information about privileges, see Privileges.

This function replaces the keys and values below the specified key with the keys and values that are subsidiary to the top-level key in the file, no matter what the name of the top-level key in the file might be. For example, hKey might identify a key A with subkeys B and C, while the lpFile parameter specifies a file containing key X with subkeys Y and Z. After a call to RegRestoreKey, the registry would contain key A with subkeys Y and Z. The value entries of A would be replaced by the value entries of X.

The new information in the file specified by lpFile overwrites the contents of the key specified by the hKey parameter, except for the key name.

If hKey represents a key in a remote computer, the path described by lpFile is relative to the remote computer.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Unsupported.
  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, RegDeleteKey, RegLoadKey, RegReplaceKey, RegSaveKey