Platform SDK: Registry |
Applications can save part of the registry in a file and then load the contents of the file back into the registry. A registry file is useful when a large amount of data is being manipulated, when many entries are being made in the registry, or when the data is transitory and must be loaded and then unloaded again. Applications that back up and restore parts of the registry are likely to use registry files.
To save a key and its subkeys and values to a registry file, an application can call the RegSaveKey function.
RegSaveKey creates the file with the following information depending upon which operating system it is running on.
Windows operating system version | File attributes | Location of saved registry if no path is specified | Error returned if a file already exists |
---|---|---|---|
Windows 95 | Archive, hidden, read-only system | Created in the Windows directory for both local and remote keys | Error code 1016, ERROR_REGISTRY_IO_FAILED |
Windows NT | Archive | Created in the current directory of the process for a local key, and in the %systemroot%\system directory for a remote key. | Error code 183, ERROR_ALREADY_EXISTS |
To write the registry file back to the registry, an application can use the RegLoadKey, RegReplaceKey, or RegRestoreKey function.
RegLoadKey loads registry data from a specified file into a specified subkey under HKEY_USERS or HKEY_LOCAL_MACHINE on the calling application's computer or on a remote computer. The function creates the specified subkey if it does not already exist. After calling this function, an application can use the RegUnLoadKey function to restore the registry to its previous state.
RegReplaceKey replaces a key and all its subkeys and values in the registry with the data contained in a specified file. The new data takes effect the next time the system is started.
RegRestoreKey loads registry data from a specified file into a specified key on the calling application's computer or on a remote computer. This function replaces the subkeys and values below the specified key with the subkeys and values that follow the top-level key in the file.
The RegConnectRegistry function establishes a connection to a predefined registry handle on another computer. An application uses this function primarily to access information from a remote registry on other machines in a network environment, which you can also do by using the Registry Editor. You might want to access a remote registry to back up a registry or regulate network access to it. Note that you must have appropriate permissions to access a remote registry using this function.
To use RegConnectRegistry on Windows 95, you need to install the remote registry service. Refer to the function specification of RegConnectRegistry for more information on how to do this.