RegReplaceKey
A version of this page is also available for
4/8/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 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.
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 data in the object store-based registry, see RegCopyFile.
Requirements
Header | pwinreg.h |
Library | coredll.lib |
Windows Embedded CE | Windows CE .NET 4.0 and later |
Windows Mobile | Windows Mobile Version 5.0 and later |
See Also
Reference
Registry Functions
RegSaveKey
RegCopyFile
RegRestoreFile
SetCurrentUser