If when you try to delete a registry key in Windows 10 or Windows Server, you are unable to delete it and you get an error message: Error while deleting key, then this article may interest you.
Error while deleting Registry key
This can be caused if you attempt to delete a registry key that contains embedded null characters. These characters are not visible when viewing the registry entry.
To delete a registry key that contains an embedded null character, you must first replace the null character with another character.
1] Use Systernals RegDelNull tool
You can accomplish this by using the RegDelNull tool from Sysinternals.
This command-line utility searches for and allows you to delete Registry keys that contain embedded-null characters and that are otherwise undeletable using standard Registry-editing tools. Deleting Registry keys may cause the applications they are associated with to fail.
2] Use Registry DeleteEx
Registry DeleteEx can delete the keys that the Registry Editor and other tools fail to do so. The tool deletes locked keys and values using a kernel-mode driver. This means any Registry value can be deleted even if it has been locked by an application or malware.
3] Take ownership and then try to delete
All the best.