RegistryKey.DeleteValue fails with UnauthorizedAccessException

From: Chris Rigg-Milner (anonymous_at_discussions.microsoft.com)
Date: 03/26/04


Date: Fri, 26 Mar 2004 03:56:07 -0800

Can somebody help? Why can I not delete a registry key value?
I have a WinForms app that needs to delete a registrykey value but fails with a UnauthorizedAccessException.
OS = XP Pro 1.1a, Framework = 1.1, language = C#

The command that fails is RegistryKey.DeleteValue(sKey,true);
This happens when using my restricted developer account and also if I run under an administrator account.
I can delete these keys using regedit quite happily from my developer account.

The namespace has the following decoration
[assembly: RegistryPermissionAttribute(SecurityAction.RequestMinimum,All = "HKEY_CURRENT_USER")]
namespace xxxx

which I assumed would allow me all the acces I required

When I look at the .exe with permview I get the following:
minimal permission set:
<PermissionSet class="System.Security.PermissionSet"
               version="1"><IPermission class="System.Security.Permissions.RegistryPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, publicKeyToken=xxxxxxxxxxxxxx"
                version="1"
                Read="HKEY_CURRENT_USER"
                Write="HKEY_CURRENT_USER"
                Create="HKEY_CURRENT_USER"/></PermissionSet>

I am basically now dazed and confused. Can anybody explain why my program fails but regedit allows this deletion. Also what do I change to get app to do the delete?

Thanks in anticipation.



Relevant Pages

  • Re: TTS Application in 5.0
    ... what error code is returned? ... > Function speak fails. ... And i noticed that the registry key ...
    (microsoft.public.windowsce.platbuilder)
  • Unable to start BITS: error 2147942403 (0x80070005)
    ... I just get aware that the reason I cannot update Windows is because of the ... Unfortunately, it fails. ... The System Event Log ... checked all registry key MS people suggested in previous posts about similar ...
    (microsoft.public.windowsupdate)
  • Re: take ownership of registry key with .NET 2.0?
    ... > modify Registry key security. ... > nothing that demonstrates how to take ownership of a Registry key if one ... > you do not have permission to do that, it fails and you get a null handle ...
    (microsoft.public.dotnet.languages.csharp)
  • take ownership of registry key with .NET 2.0?
    ... nothing that demonstrates how to take ownership of a Registry key if one ... you do not have permission to do that, it fails and you get a null handle ... And try to open my sub key, which I only have "write owner" permission ...
    (microsoft.public.dotnet.languages.csharp)