Generally speaking, yanking the power plug unexpectedly should not be part of your business process
A customer had a complex process for setting up their computers, and the process recorded information in the registry so that applications could record their state across reboots. They then noticed that if they yanked the power cord instead of going through the normal Shutdown process, that the registry keys were not reliably updated. They were wondering if there was a function they can call to force the registry to be flushed to disk even if the system doesn’t go through a normal shutdown.
Patient: “Doctor, it hurts when I do this.”
Doctor: “Don’t do that.”
You could call the
RegFlushKey function each time you update the registry key, but you’ll be flushing your performance down the drain.
RegFlushKey doesn’t solve the “unexpected power loss” problem entirely. If power is lost while the key is being flushed, then you can end up with internal registry corruption. Not to mention that cutting power will corrupt the hard drive due to unflushed data both in the operating system disk cache as well as the hard drive’s on-board disk cache.
It’s like somebody who says, “We never save our documents; we just let Excel AutoSave find the document each time we startup Excel. We found that if we yank the power cord to turn off the computer, sometimes when we boot the computer back up, the Excel document we were working on doesn’t show up in the AutoSave recovery dialog. How can we force Excel to AutoSave our document before we yank the power cord?”
Dude, your problem isn’t a configuration problem with AutoSave. Your problem is that you’re yanking the power cord as part of your business process.
The customer reported back that, thankfully, killing power was not part of their normal procedures. Rather, the issue with unexpected power loss was something they discovered by accident.
Sigh of relief.