Share via


RegSaveKey (Windows CE 5.0)

Send Feedback

This function saves the specified key and all of its subkeys and values to a new file. If the specified key is not a predefined ROOT, it backs up to the ROOT of the hKey and saves there.

LONGRegSaveKey(HKEYhKey,LPCTSTRlpFile,LPSECURITY_ATTRIBUTESlpSecurityAttributes);

Parameters

  • hKey
    [in] Specifies a handle to the key where the save operation is to begin, or any of the following predefined reserved handle values:
    • HKEY_CLASSES_ROOT
    • HKEY_CURRENT_USER
    • HKEY_LOCAL_MACHINE
    • 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 NULL.

Return Values

If the function succeeds, the return value is ERROR_SUCCESS.

The function may fail with GetLastError returning ERROR_NOT_SUPPORTED because it is not supported on the object store-based registry.

If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

Remarks

The RegSaveKey API is only supported by the hive-based registry. To save and restore data in the object store-based registry, see RegCopyFile and RegRestoreFile.

While you can call RegSaveKey with any registry key, in effect 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_USER or 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 RegSaveKey in subsequent calls to RegReplaceKey with HKEY_LOCAL_MACHINE to 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 in. Subsequent calls to SetCurrentUser will use the restored hive.

Requirements

OS Versions: Windows CE .NET 4.0 and later.
Header: Pwinreg.h.
Link Library: Coredll.lib.

See Also

RegReplaceKey | SetCurrentUser | FormatMessage | RegCopyFile | RegRestoreFile | Persisting Data with the Hive-Based Registry

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.