OpenSubkey permission exception RRS feed

  • Question

  • I'm trying to open a registry key with the code below: 
       RegistryKey obj = RegistryKey.OpenBaseKey (RegistryHive.LocalMachine, RegistryView.Registry32) OpenSubKey (@ "SOFTWARE \ CREATE \ FRAMEWORK", true).; 
    But even when logged in as administrator and request that permission also be manifest in the application, I keep getting the following error: 
    Error type: System.Security.SecurityException 'occurred in mscorlib.dll 
    Additional information: Access to the registry requested is not allowed.

    Wednesday, March 12, 2014 6:52 PM

All replies

  • It only occur on debug mode
    Wednesday, March 12, 2014 7:19 PM
  • You're trying to open the x86 view of the HKLM\Software\Create\Framework registry key for write access.  Is there a particular reason why you need that view instead of the standard view?  When you log in as an admin are you running with elevated privileges?  If not then it likely will fail.  You will need to run your app elevated.

    Michael Taylor

    • Proposed as answer by Fred Bao Friday, March 21, 2014 6:27 AM
    Wednesday, March 12, 2014 8:30 PM
  • Yes there is a reason to open up the x86 view, the application creates a key in the Wow6432Node node. How to run my application with elevated privileges ? Remembering that when compiled in realese mode everything works normally.
    Wednesday, March 12, 2014 8:46 PM
  • Debug vs release build has no impact on permissions.  It likely changes how you're running your app though.  Have you tried running both your debug and release builds outside of VS using an elevated command prompt?
    Wednesday, March 12, 2014 8:55 PM