spez
spez

Reputation: 469

Deleting registrry subkey doesnt delete,no error was throwed

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)

Upvotes: 1

Views: 257

Answers (1)

TheGeneral
TheGeneral

Reputation: 81493

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))
{

}

Upvotes: 1

Related Questions