I have an application that needs to delete a subkey tree and readd the entries. The tree may have values changed or additional values added and I need to reset to the default state. When I delete the subtree with key.DeleteSubKeyTree() everything works great until I attempt to readd the base registry settings. At this point I get Illegal Operation error (illegal operation attempted on a registry key that has been marked for deletion).
So, how can I close/flush the deleted entries? Looks like all the delete operations operate on subkeys/values by name, not reference so I can’t directly close it. I am closing the root key.
Due to the values that may have been added, I do need to delete and not just set the values so the added keys (ones not in the base registry) are cleared from the registry.
After a little more experimentation, I was able to perform the task by indvidually deleting all the values and then deleting the subkeys. Here’s a recursive routine to do it: