1

I am trying to delete some registry key via C#, but to code doesn't effect about the registry, I opened Visual Studio as administrator, I am trying to delete a key located in this path:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects

enter image description here

Here my code:

string RegBHO = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";
string guid = "{b908e54f-8c58-4d5d-8762-60d7d675cd39}";
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(RegBHO, true);
registryKey.DeleteSubKey(guid, false);

But the folder named {b908e54f-8c58-4d5d-8762-60d7d675cd39} still exist enen after I run the code (I clicked F5 to refresh registry list)

Community
  • 1
  • 1
spez
  • 409
  • 8
  • 21
  • Does this answer your question? [Delete a Registry key using C#](https://stackoverflow.com/questions/32250244/delete-a-registry-key-using-c-sharp) – Nouman Feb 18 '20 at 08:33
  • Can you manually create the key `HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects\{b908e54f-8c58-4d5d-8762-60d7d675cd39}` and run your program to see if it's deleted ? – Cid Feb 18 '20 at 08:34

1 Answers1

1

More than likely you are trying to delete a 32bit key from a 64bit application or vice-versa.

You will need to use the appropriate bitness in your app, or use the following to read / write / Delete the keys

RegistryView Enum

Specifies which registry view to target on a 64-bit operating system.

with

RegistryKey.OpenBaseKey

Opens a new RegistryKey that represents the requested key on the local machine with the specified view.

RegistryView Enumeration : On the 64-bit version of Windows, portions of the registry are stored separately for 32-bit and 64-bit applications. There is a 32-bit view for 32-bit applications and a 64-bit view for 64-bit applications.

You can specify a registry view when you use the OpenBaseKey and OpenRemoteBaseKey(RegistryHive, String, RegistryView) methods, and the FromHandle property on a RegistryKey object.

Example

using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
{

}
TheGeneral
  • 79,002
  • 9
  • 103
  • 141