How is it possible to get ERROR_KEY_DELETED when I’m creating a key?

The key that got deleted is not the one you are trying to create. The post How is it possible to get ERROR_KEY_DELETED when I’m creating a key? appeared first on The Old New Thing.

Jan 14, 2025 - 13:36
How is it possible to get ERROR_KEY_DELETED when I’m creating a key?

Some time ago, I explained that the ERROR_KEY_DELETED error code means that you tried to perform an operation on a deleted key. But what does it mean when you get the error when trying to create a key?

The key it’s complaining about is not the key you’re trying to create. The problem is with the key that you are trying to create the key beneath.

auto err = RegCreateKeyEx(parentKey, subkeyName,
    0, nullptr, REG_OPTION_NON_VOLATILE, KEY_WRITE, nullptr, &childKey);

If the parent key is deleted, then any future attempt to use that parent key (including creating child keys under it) will return ERROR_KEY_DELETED.

We’ll look into this some more next time.

The post How is it possible to get ERROR_KEY_DELETED when I’m creating a key? appeared first on The Old New Thing.