1

I would like to delete the following node from the registry. How can I do it?

HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{D9AC2148-5E15-48AD-A693-E48714592381}

I have this much:

string key = "D9AC2148-5E15-48AD-A693-E48714592381";
StringBuilder sb = new StringBuilder(key);
RegistryKey k = Registry.ClassesRoot.OpenSubKey("Wow6432Node\\CLSID", true);

How do I proceed?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rauf
  • 12,326
  • 20
  • 77
  • 126

2 Answers2

2

You need to take into account registry redirection; that's the real issue here. On a 32-bit machine, the key you need doesn't have WoW6432Node in the path.

You are trying to delete

HKEY_CLASSES_ROOT\CLSID\{D9AC2148-5E15-48AD-A693-E48714592381}

from the 32-bit view of the registry. Microsoft is very clear that you should not hard code WoW6432Node in your applications:

Redirected keys are mapped to physical locations under Wow6432Node. For example, HKEY_LOCAL_MACHINE\Software is redirected to HKEY_LOCAL_MACHINE\Software\Wow6432Node. However, the physical location of redirected keys should be considered reserved by the system. Applications should not access a key's physical location directly, because this location may change.

So delete that key by calling

DeleteSubKey(@"HKEY_CLASSES_ROOT\CLSID\{D9AC2148-5E15-48AD-A693-E48714592381}")

But use the redirector to ensure that you operate on the 32-bit view of the registry.

In .NET you can achieve what you need in two ways.

  1. Target x86 and let redirection do the work for you.
  2. If you target x64 or AnyCPU, you need to use RegistryView.Registry32 (new in .NET 4) to open a 32-bit view of the registry. If you don't have .NET 4 then you have to P/Invoke.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
1

You could use the DeleteSubKey method:

string key = "{D9AC2148-5E15-48AD-A693-E48714592381}";
Registry.ClassesRoot.DeleteSubKey(@"Wow6432Node\CLSID\" + key);
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • @Darin Dimitrov What does the braces which wraps the GUID means. When I used without braces, I could not open the sub-key. But I used {D9...81}, I could open it. – Rauf Sep 16 '11 at 09:05
  • @Rauf, they are just part of the name so should be included. – Darin Dimitrov Sep 16 '11 at 09:12