Error accessing Registry from Windows app

Discussion in 'ASP .Net Security' started by Steve, Nov 29, 2003.

  1. Steve

    Steve Guest

    When attempting to access the Registry, I receive errors.
    I have attempted to add code to assert access to the key,
    but this does not help. The documentation on accessing
    the Registry is pathetic.

    Dim rp As New
    System.Security.Permissions.RegistryPermission
    (Security.Permissions.RegistryPermissionAccess.AllAccess,
    "HKEY_CURRENT_USER\SOFTWARE\MyApplication")
    oKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey
    ("Software").OpenSubKey("MyApplication").OpenSubKey
    ("Database")
    oKey.SetValue("Databases", "1")


    Error Message:

    An unhandled exception of
    type 'System.UnauthorizedAccessException' occurred in
    mscorlib.dll

    Additional information: Cannot write to the registry key.
    Steve, Nov 29, 2003
    #1
    1. Advertising

  2. Steve

    Paul Glavich Guest

    Use the Regedt32 tool (in Win2000) or Regedit (WinXP) to set read/write
    access on the particular registry key for the user your are trying to access
    with, or the group that the user(s) are a member of.

    --
    - Paul Glavich


    "Steve" <> wrote in message
    news:002501c3b6a7$19f84300$...
    > When attempting to access the Registry, I receive errors.
    > I have attempted to add code to assert access to the key,
    > but this does not help. The documentation on accessing
    > the Registry is pathetic.
    >
    > Dim rp As New
    > System.Security.Permissions.RegistryPermission
    > (Security.Permissions.RegistryPermissionAccess.AllAccess,
    > "HKEY_CURRENT_USER\SOFTWARE\MyApplication")
    > oKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey
    > ("Software").OpenSubKey("MyApplication").OpenSubKey
    > ("Database")
    > oKey.SetValue("Databases", "1")
    >
    >
    > Error Message:
    >
    > An unhandled exception of
    > type 'System.UnauthorizedAccessException' occurred in
    > mscorlib.dll
    >
    > Additional information: Cannot write to the registry key.
    Paul Glavich, Nov 30, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HK
    Replies:
    1
    Views:
    3,622
    Cowboy \(Gregory A. Beamer\)
    Apr 1, 2004
  2. Replies:
    0
    Views:
    747
  3. Leny
    Replies:
    3
    Views:
    16,917
    Daniel
    Feb 1, 2005
  4. Wanda
    Replies:
    2
    Views:
    250
    Wanda Li
    Aug 12, 2004
  5. Collin Miller
    Replies:
    10
    Views:
    591
    Roger Pack
    Jul 9, 2010
Loading...

Share This Page