Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,

I am unable to delete a particular registry key from Win 7 64 bit. The deletion command result is successful but when i go and check in registry, the entry exists.
In Win7 32 bit and other OS, it runs fine-deletes successfully. The problem is in 64 bit OS.
Below is the code snippet:

C#
RegistryKey registrykeyHKLM = Registry.LocalMachine;
          string keyPath = @"Software\Microsoft\Windows\CurrentVersion\Uninstall\InstallShield_{3BFAF362-6DB8-46EA-98BB-713388534EB1}";

          RegistryKey rk2 = Registry.LocalMachine.CreateSubKey(keyPath);

          if (rk2 != null)
          {
              errlog.WriteLogMsg("Found the registry: " + keyPath);
              // Deleting uninstall registry key entries
              registrykeyHKLM.DeleteSubKey(keyPath);
          }

          rk2.Close();
          registrykeyHKLM.Close();

          //Checking for successful deletion of Uninstall registry keys
          try
          {
              RegistryKey rk = Registry.LocalMachine.OpenSubKey(keyPath,true);

              if (rk != null)
              {
                  errlog.WriteLogMsg("Registry found. Unable to delete registry key: " + keyPath);
                  errlog.WriteLogMsg("Failed to delete Uninstall Information Registry Entries!!!");
                  //MessageBox.Show("Failed to delete Uninstall Information Registry Entries!!!");//2.0.0 (DKD)
              }
              else
              {
                  errlog.WriteLogMsg("Successfully deleted registry key: " + keyPath);
              }
          }
          catch (Exception ex1)
          {
              errlog.WriteLogMsg("Exception while deleting registry entries");
              errlog.WriteErrorLog(ex1);
          }


NOTE: The registry entry which i am trying to access is not in Wow6432 node.. its in a common place in both 64 & 32 bit machines. But still i am not able to delete that particular key in 64 bit machine. The keyPath which iam trying to access is common for both 64 bit and 32 bit,i can read,modify the value but iam not able to Delete the key

Please help
Thanks & regards
Dinesh
Posted
Updated 13-May-13 0:02am
v3

1 solution

Try it with this version of the delete[^], and catch any exceptions that are raised.
 
Share this answer
 
Comments
[no name] 13-May-13 5:26am    
Thanks Richard for the prompt reply.
I tried that but i am not getting any exception. Is there any alternative solution ?
Richard MacCutchan 13-May-13 5:54am    
I have just tried your code and it works without error. Can you update your question (use the "Improve question" link), and show thae actual contents of the key, and the values you are using in your code.
[no name] 13-May-13 6:03am    
I have updated the question and had shown the keyPath. This path is common for both 64 and 32 bit PC. I can read,modify the value of the regkey but i am not able to delete it. :(
Richard MacCutchan 13-May-13 6:11am    
I can't see any reason that makes that key special, unless it has some extra protection level known only to Microsoft.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900