다음을 통해 공유


RegReplaceKey (Windows Embedded CE 6.0)

1/6/2010

This function replaces the file backing a registry key and all its subkeys with another file, so that when the system is next started, the key and subkeys have the values stored in the new file.

Syntax

LONG RegReplaceKey( 
  HKEY hKey,
  LPCTSTR lpSubKey,
  LPCTSTR lpNewFile,
  LPCTSTR lpOldFile
);

Parameters

  • hKey
    [in] Must be set to HKEY_LOCAL_MACHINE.
  • lpSubKey
    [in] Must be set to NULL.
  • lpNewFile
    [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. This value can be set to set to NULL.
  • lpOldFile
    [in] Pointer to a null-terminated string containing the name of a file that receives a backup copy of the registry information being replaced. This value can be set to NULL.

Return Value

If GetLastError returns the value of the function or ERROR_NOT_SUPPORTED, this function is not supported on the object store-based registry.

If GetLastError returns ERROR_ACCESS_DENIED, only privileged applications can call this function.

If the input file does not have the attribute FILE_ATTRIBUTE_SYSTEM, the GetLastError function will return ERROR_INVALID_PARAMETER.

Remarks

This function can be used only to restore a backup copy of the system registry hive, which contains all data under HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT, and HKEY_USERS. To restore a saved user hive, move the file into the user's profile directory while the user is not logged on. Subsequent calls to the SetCurrentUser function use the restored hive.

The system hive is unmounted and is not remounted until the system is restarted. This means that the system registry becomes unusable. Both files remain closed after this call. The current registry hive is moved to lpOldFile.

If lpNewFile is non-NULL, that file is renamed to be the registry hive and is mounted when the system is restarted.

If lpNewFile is set to NULL, a default hive is loaded from ROM when the system is restarted.

This function is supported only only for a hive-based registry. To save and restore data in the object store-based registry, see RegCopyFile and RegRestoreFile.

Requirements

Header pwinreg.h
Library coredll.lib
Windows Embedded CE Windows CE .NET 4.0 and later

See Also

Reference

Registry Functions
RegSaveKey
RegCopyFile
RegRestoreFile
SetCurrentUser

Concepts

Data Persistence with the Hive-Based Registry