Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7802119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:09:54+00:00 2026-06-02T01:09:54+00:00

I have an application that needs to delete a subkey tree and readd the

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:09:56+00:00Added an answer on June 2, 2026 at 1:09 am

    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:

         /// <summary>
         /// Deletes all the values and subkeys of a particular key.
         /// </summary>
         /// <param name="key"></param>
         private static void DeleteRegistrySubStructure(RegistryKey key)
         {
             // First, traverse the subkeys to delete the underlying values and subkeys.
             String[] subKeys = key.GetSubKeyNames();
             foreach (var subKeyName in subKeys)
             {
                 RegistryKey subKey = key.OpenSubKey(subKeyName, true);
                 DeleteRegistrySubStructure(subKey);
                 subKey.Close();
                 key.DeleteSubKey(subKeyName);
             }
    
             // At this point, all the subkeys (and their values) have been 
             // deleted.  So, delete the values for the key for final clean up. 
             string[] valueNames = key.GetValueNames();
             foreach (string name in valueNames)
             {                
                 key.DeleteValue(name);
             }
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application that needs to know the path that it is executed
I have an application that needs to send a moderately high volume of messages
I have an application that needs to hit the ActiveDirectory to get user permission/roles
I have an application that needs to poll a webservice to see if the
we have an application that needs to send out various different types of template
I have an application that needs to work with a vendor-supplied API to do
I have an application that needs to check a website feed every second. Sometimes
I have an application that needs to highlight individual pixels on an image. I
I have an application that needs to determine whether a user has made a
I have an application that needs branding when downloaded in certain continents. When installed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.