none
System.UnauthorizedAccessException

    Question

  • Hi there,

    I'd incorporated a feature to receive email on getting unhandled exceptions in my c# program. I'd created a manifest file so that the program was getting administrative privileges via UAC when being run on Vista or 7.

    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

    However, i was surprised to see the error report showing System.UnauthorizedAccessException when creating(opening a key for write access) and i'm absolutely puzzled on how to fix it.

    Here's more information:

    Message: Denied access to the registry key "HKEY_CURRENT_USER \ Control Panel \ Desktop".

    Source: mscorlib

    StackTrace:

     in Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
      in Microsoft.Win32.RegistryKey.CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck, RegistrySecurity registrySecurity)
      
    in Microsoft.Win32.RegistryKey.CreateSubKey(String subkey)

      in Windows7_Tweaker.Form1..ctor()

     

    I use the first overload of CreatedSubKey , eg. RegistryKey r=regkey.CreateSubKey("Desktop");

    Thanks


    sidmkp96
    Wednesday, January 05, 2011 11:19 AM

Answers

  • this looks more on Rregistry permission for the user. you need to enable Write access for the user from 'egistry Permission'

    Regedit->Edit->Permissions . Modify this if required.

    Wednesday, January 05, 2011 11:47 AM