Compartilhar via


Persisting Data with the Hive-Based Registry (Windows CE 5.0)

Send Feedback

The hive-based registry is designed to relieve the OEM of persisting the registry. No work is necessary on boot or shutdown to preserve registry data, with the possible exception that the OEM may need to flush the registry using RegFlushKey if a typical software shutdown is not done.

Some additional options are available if the OEM wants to perform a final backup. This may be necessary if the data stored in the registry renders the system somehow not viable. In this case, the OEM can use RegSaveKey to save a known viable registry, and use RegReplaceKey to restore it. This solution requires a system reboot after calling RegReplaceKey, but should only be necessary in rare cases.

RegSaveKey operates on one hive at a time; calling this API on HKEY_LOCAL_MACHINE will save the system hive to a file, and calling it on HKEY_CURRENT_USER will save the current user's hive. Conversely, RegReplaceKey can only be used with HKEY_LOCAL_MACHINE. It replaces the system hive only. To replace a user hive, the OEM may call SetCurrentUser with a NULL user name to log off the current user, and then call CopyFile to replace the user's invalid hive with a saved known viable hive.

Another case in which last known good support is useful is the case in which the registry hive files become corrupted, perhaps by a file system error. When the system detects a corrupt hive file during boot, the file is deleted and a clean one created in its place. This enables the system to boot successfully. You can detect this event by looking for a particular value under HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER, as shown in the following registry key example.

[HKEY_LOCAL_MACHINE]
    "RegPersisted"=dword:1

If this value is present under HKEY_LOCAL_MACHINE, it indicates that the system hive has been restored successfully. If it is present under HKEY_CURRENT_USER, it indicates that the user hive was successfully restored. Its absence indicates a clean boot, in which case the hive was created new. If the value is absent, you can set up verification for this value and restore a stored last known hive.

See Also

Hive-Based Registry | Using the Hive-Based Registry | Troubleshooting the Hive-Based Registry | Hive-Based Registry Data

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.