Deleting a Registry Keys

  • 13 years ago

    Im trying to write code to delete a subkey (including all values stored under it), see snippet below:

    .....
    Dim rKey as RegistryKey


    rKey = Registry.Classes_Root
    rKey = rKey.OpenSubKey("CLSID",true)
    rKey.DeleteSubKey("{227FE4FD-9D11-4DA1-A1C0-3F0BB9AF21EC}")
    ...


    But when I run this it raises the following:

    'System.UnauthorizedAccessException' occurred in mscorlib.dll
    "Cannot write to the registry key"

    Any ideas what I'm doing wrong, would be most grateful.

    Thanks..... 

  • 13 years ago

    1. You are not logged on as an administrator

    2. You are trying to delete a key without the necessary permissions, try adding the <System.Security.Permissions.RegistryPermissions({param}) attribute at either class or method level.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Every language has an optimization operator. In C++ that operator is ‘//’”