add administrators to windows 7 registry key


  • Hello, I am writing a very specific program that checks and changes some registry keys in the HKEY_CURRENT_USER\Control Panel\Desktop key. I've had no issues with this in vista\ or xp. but windows 7 gives me permission errors. 

    the problem is that Administrators group is missing from the permissions table in the registry for this key. I can fix this by opening regedit and right clicking permissions for this key and adding Administrators to the table. However I don't want the end user to have to do this.

    so how can I add administrators group to the permissions table of this key using code?

    Everywhere I look online people say don't write to this part of the registry if I don't have to. well I have to as it is a windows key that I must change. all permissions are set correctly for the program I just need to know how to add administrators to the permissions list in the registry in windows 7 using

    Monday, May 14, 2012 4:11 PM


All replies


    I don't need to give you any specific code but tailor the code in the link above to your needs.

    - Jordan

    Jordan St. Godard | Microsoft® Community Contributor 2011

    double twoCents = .02;
    Console.WriteLine("$" + twoCents.ToString());

    Monday, May 14, 2012 4:54 PM
  • Here is a link on the RegisteryPermission object, with a sample on how to add a perm to a key.

    good luck. I can't guarantee it will work in the end. I wouldn't expect the controlpanel to be volatile, but there are some parts of the registry that you simply won't be able to alter (and in most cases read), and other parts where you have to write upon each boot, because some of the values are derived dynamically.

    • Edited by Endotherm Tuesday, May 15, 2012 1:24 AM
    Tuesday, May 15, 2012 1:21 AM
  • Unless you turn off UAC (User Account Control), it is not possible to make those Registry changes without running the app with elevated privileges (as an Administrator). The below article demonstrates how:

    I had no problem when modifying entries when running Regedit elevated, as an Administrator.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    • Proposed as answer by btickle1 Wednesday, May 16, 2012 3:56 PM
    • Marked as answer by Youen ZenModerator Thursday, May 24, 2012 8:06 AM
    Tuesday, May 15, 2012 12:41 PM
  • Have you made sure the user is in the administrators group in local users and groups because if their not their using that code above might bring a access denied or equivilent error.  To get to local users and groups right clic my computer->manage->local users and groups->groups->administrators and add user to that group to be sure your program can edit the registry. I believe unlike windows xp this is required in windows 7.

    Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog -

    • Edited by The Thinker Thursday, May 17, 2012 1:18 PM
    • Proposed as answer by The Thinker Thursday, May 17, 2012 1:18 PM
    Thursday, May 17, 2012 1:18 PM