| Previous | Next |
| ERROR_BADDB | ERROR_CANTOPEN |
ERROR_BADKEY
The registry operation received an invalid key
Registry APIs operate on predefined root handles or handles returned by successful open/create calls. ERROR_BADKEY indicates that the key context itself is invalid for the attempted configuration-registry operation. It is therefore different from ERROR_CANTOPEN, where Windows failed to open a named key, and from ERROR_KEY_DELETED, where a previously valid key has entered deletion state.
Audit handle lifetime and the exact API sequence. A stale, overwritten, incorrectly marshalled, or never-initialized HKEY can make later reads and writes fail before the value name is relevant. In code that switches between local and remote registry contexts, also verify that handles are not reused after the owning connection or hive is closed. Log the root key, subkey string, return value from the open/create call, and the point where RegCloseKey executes.
What to inspect
- Verify every HKEY originates from a successful open/create operation.
- Check for use after RegCloseKey and accidental handle overwrites.
- Distinguish invalid-handle state from a missing subkey name.
References
Looking for a different code? Search another status or error code.