Results 1 to 4 of 4

Thread: UnauthorisedAccessException

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2008
    Posts
    1

    UnauthorisedAccessException

    Hi ,
    I am trying to change the datavalue of a registry key using dotnet c#

    The code i use is as follows
    RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Shared Tools\\Web Server Extensions\\12.0\\WSS");
    if (key != null)
    {
    key.SetValue("SetupType","V2V_INPLACE_UPGRADE");
    f1.Logger("Registry value in the key SetupType is succesfully set as V2V_INPLACE_UPGRADE");
    }
    How ever i am not able to set the value as an unhandled exception gets thrown UnauthorisedAccessException saying i dont have the access privileges .
    how ever i am the administrator and i am able to change the registry settings manually .

    kindly help me out regarding this .

    Thanks in advance
    have a nice day

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: UnauthorisedAccessException

    Read the MSDN documentation for the OpenSubKey method. Pay particular attention to the description of the overload you're calling:
    Quote Originally Posted by MSDN
    Retrieves a subkey as read-only.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: UnauthorisedAccessException

    Moved and duplicate thread removed

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: UnauthorisedAccessException

    I had replied to the duplicate thread that was removed so I'll repost that info here. As I have already said, the OpenSubKey method you're calling opens the key read-only. As you'd expect, writing to a read-only key is a no-no. So, doing as I said and going to the MSDN documentation for the OpenSubKey method you'll see that there are several overloads. You know the one you're calling is no good so look at the others. Do any of them allow you to open the key without the read-only restriction?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width