locked
Access to registry key is denied RRS feed

  • Question

  • Hi,

    I got this "Access to registry key is denied" error when my user tried to run the win form app I developed.  

    On the Login form, I have following lines of code that will read/save user login name in the registry.
         
    LoginName = Microsoft.Win32.Registry.Users.GetValue("CSRTSName", LoginName).ToString
    Microsoft.Win32.Registry.Users.SetValue("CSRTSName", LoginName)

    The purpose of this is to save last logon user's name into registry, and on next logon, the same user doesn't have to type in logon name.

    This works on my dev machine and any other users who have admin privilage. But to everage users, I got above error.

    How do I grant permission to my code?

    By the way, I did not find that key on my own machine.
    Thursday, August 3, 2006 2:13 PM

Answers

  • Instead of writing to HKEY_USERS directly via Microsoft.Win32.Registry.Users, try storing your data in HKEY_CURRENT_USER via Microsoft.Win32.Registry.CurrentUser.

    As you've found the system enforces certain limitations on different users to different parts of the registry and having access to the entire HKEY_USERS tree is generally only permitted with Admin access... the HKEY_CURRENT_USER tree on the other hand (which is really a sub tree of HKEY_USERS) is generally able to be written to by the user account that owns it.

    Thursday, August 3, 2006 2:41 PM

All replies

  • Instead of writing to HKEY_USERS directly via Microsoft.Win32.Registry.Users, try storing your data in HKEY_CURRENT_USER via Microsoft.Win32.Registry.CurrentUser.

    As you've found the system enforces certain limitations on different users to different parts of the registry and having access to the entire HKEY_USERS tree is generally only permitted with Admin access... the HKEY_CURRENT_USER tree on the other hand (which is really a sub tree of HKEY_USERS) is generally able to be written to by the user account that owns it.

    Thursday, August 3, 2006 2:41 PM
  • Great! Thanks!
    Thursday, August 3, 2006 3:17 PM