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
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.
Re: UnauthorisedAccessException
Moved and duplicate thread removed
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?