A customer discovered through telemetry that their program was failing with the error code ERROR_
when they try to set a value in the registry. What does this error mean?
When you open a registry key, you get a handle, and that handle refers to the key you opened. If somebody deletes that registry key, your handle remains a valid handle, but all operations on it fail with ERROR_
. The only thing you can do with the handle is close it.
The registry allows a key to be deleted despite there being open handles to it because the inability to lock someone out of the registry is a feature, not a bug. The deletion succeeds, and all existing handles are now told, “Sorry, that key no longer exists.”
Note that if somebody creates a new key with the same name as the deleted key, that does not revive the deleted key. The new key is a different key that just happens to have the same name as the deleted yet. It’s not the same key. (It shouldn’t be considered the same key because the security descriptor on the new key may not be the same as the security descriptor on the old key.)
In the customer’s case, the program opened the registry key when the program started and kept it open until the program ended. There is no code in the program to delete the key, so my guess is that what happened is that the user opened regedit and manually deleted the key, perhaps in a well-intentioned but misguided attempt to reset all settings to their defaults.
I also see this error code in our telemetry (not extremely often but not that seldom to consider it noise). Weird thing is:
- the error is returned when opening the key, i.e. the handle doesn't exist yet
- the key in question is HKEY_CURRENT_USER\Software ... i.e. something I really wouldn't expect to get deleted.
I was wondering if the user is being logged off and the HKEY_CURRENT_USER hive got unloaded (if that might cause this error code), or maybe some "registry optimization tool" it trying to replace HKEY_CURRENT_USER\Software with a different version... but it's all just wild speculation.