Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function saves the specified key and all its subkeys and values to a new file. If the specified key is not a predefined root, it saves to the root of the hKeyparameter.

Syntax

LONG RegSaveKey( 
  HKEY 
hKey,
  LPCTSTR 
lpFile,
  LPSECURITY_ATTRIBUTES 
lpSecurityAttributes
);

Parameters

hKey

[in] Specifies a handle to the key in which the save operation is to begin or any of the following predefined reserved handle values:

  • HKEY_LOCAL_MACHINE

  • HKEY_CLASSES_ROOT

  • HKEY_CURRENT_USER

  • HKEY_USERS

lpFile

[in] Pointer to a null-terminated string containing the name of the file in which the specified key and subkeys are saved.

lpSecurityAttributes

[in] Must be set to NULL.

Return Value

ERROR_SUCCESS indicates success. A nonzero error code defined in Winerror.h indicates failure. To get a generic description of the error, call the FormatMessagefunciton with the FORMAT_MESSAGE_FROM_SYSTEM flag set.

If GetLastErrorreturns ERROR_NOT_SUPPORTED, this function is not supported on an object store-based registry.

Remarks

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

Although you can call this function with any registry key, it only provides two choices. If it is called with HKEY_LOCAL_MACHINE, HKEY_CLASSES_ROOT, HKEY_USERS, or any key under those roots, it saves a copy of the entire system hive, which includes all keys under these roots. If it is called with HKEY_CURRENT_USERor any key under it, it saves a copy of the entire user hive, which includes all keys under HKEY_CURRENT_USER.

You can use the file created by this function in subsequent calls to the RegReplaceKeyfunction with HKEY_LOCAL_MACHINEto restore the system registry hive. 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 SetCurrentUserfunction use the restored hive.

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