Writing into registry using as a standard user RRS feed

  • Question

  • Hi,

    My applciation throws error while writing into registry

    Below is the code...

                RegistryKey rk = Registry.ClassesRoot;
                RegistryKey sk1 = rk.OpenSubKey(".log", true);

                RegistryKey sk2 = rk.OpenSubKey(".log\\PersistentHandler", true);
                sk2.SetValue("", "{5e941d80-bf96-11cd-b579-08002b30bfeb}");

    This works fine if the application is run on a machine where user is logged on a sadmin user.

    But this fails if it is run with standard user login.

    Ho can i fix this?

    Tuesday, July 24, 2012 6:50 AM


All replies

  • Are you impersonating the user who is logged in or is it the user account running application pool that can not access the registry?

    Any how the standard user has now rights to use the registry, so you need to change the configuration. Good way is to access registry with specified user account so you don't need to give registry access to every user if impersonation is used, but how you solve this depends on your current configuration about the identity that access the registry.

    ASP.NET security forums at is more appropriate place for this question.

    • Edited by MasaSam Tuesday, July 24, 2012 7:02 AM
    Tuesday, July 24, 2012 6:59 AM
  • This is a .net windows application. I have logged on to the windows machine as a standard user.

    and then just running the application exe by double clicking it.

    Wht is the exact configuration I have to do? FYI, this application will be deployed in multiple desktops.Please suggest!

    Tuesday, July 24, 2012 8:19 AM
  • So is it a Windows Forms/WPF application or ASP.NET application? The title is about ASP.NET. If it's desktop application, then the user using the application would need permissions to make registry modifications.

    Tuesday, July 24, 2012 8:45 AM
  • Hi Shanthi,

    Welcome to the MSDN Forum.

    Please check the permission of this key, it may have set access control:, so you need to open it with specific user account:

    Best regards,

    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 25, 2012 9:16 AM
  • The ClassesRoot hive is typically secured to prevent changes by a standard user.  This is to prevent a virus or trojan from making unauthorized changes.

    The best solution is to move the above code to an installer which would be run by a user with administrative rights. 

    This signature unintentionally left blank.

    Wednesday, July 25, 2012 10:58 AM