Data Persistence with the Hive-Based Registry (Windows Embedded CE 6.0)

1/6/2010

With the hive-based registry, the OEM does not need to persist the registry. No work is necessary on startup or shutdown to preserve registry data, with the possible exception of flushing the registry with RegFlushKey if a typical software shutdown is not done.

Some additional options are available 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 restart after calling RegReplaceKey, but should only be necessary in rare cases.

RegSaveKey operates on one hive at a time. Calling this function on HKEY_LOCAL_MACHINE saves the system hive to a file, and calling it on HKEY_CURRENT_USER saves the current user's hive. Conversely, RegReplaceKey can be used only with HKEY_LOCAL_MACHINE. It replaces only the system hiv. To replace a user hive, the OEM can call SetCurrentUser with user name of NULL to log the current user off, 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 when 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 start 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-good hive.

See Also

Tasks

Implementing the Hive-Based Registry

Concepts

Hive-Based Registry
Troubleshooting the Hive-Based Registry