Home All Groups Group Topic Archive Search About

c# cannot change registry value

Author
21 Feb 2007 10:33 PM
Chris
I have Visual Studio 2005 Express Edition. I am trying to change registry
value by:

RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\My_app");
key.SetValue(name_of_value, new_value_string);

I am getting error:


System.UnauthorizedAccessException: Cannot write to the registry key.
   at System.ThrowHelper.ThrowUnauthorizedAccessException(ExceptionResource
resource)
   at Microsoft.Win32.RegistryKey.SetValue(String name, Object value,
RegistryValueKind valueKind)
   at Microsoft.Win32.RegistryKey.SetValue(String name, Object value)
   at MyApp.Form1.MyFunction(String data, String name_of_value) in
C:\Documents and Settings\Admin\MyApp\MyApp\Form1.cs:line 70



what is wrong?

Author
27 Feb 2007 10:30 PM
Bud Bundy
When you use OpenSubKey you are opening registry keys in read-only mode.  Just make this change to your code,

RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\My_app", true);

Good luck!!

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Are all your drivers up to date? click for free checkup

Author
19 Dec 2008 7:19 AM
umesh chape
I want to do following task by using c#.

Run -   regedit
Navigate path - HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY
Rightclick --> new>DWORD>
add key ExtensionHardening
value = 0

For that propose i write following code:

RegistryKey regkey;
        regkey = Registry.CurrentUser.OpenSubKey("HKEY_CURRENT_USER\\SOFTWARE\\MICROSOFT\\OFFICE\\12.0\\EXCEL\\SECURITY", true);

But i get regkey value is null.

what is wrong in above code.
Author
19 Dec 2008 8:41 AM
Stanimir Stoyanov
"HKEY_CURRENT_USER" should not be included in your registry key path because
it is relative (in this case you are already using Registry.CurrentUser so
it is redundant). =>

RegistryKey regkey =
Registry.CurrentUser.OpenSubKey("SOFTWARE\\MICROSOFT\\OFFICE\\12.0\\EXCEL\\SECURITY",
true);
--
Stanimir Stoyanov
http://stoyanoff.info

"umesh chape" wrote in message
Show quoteHide quote
news:2008121921932umesh.chpe@aurovision.com...
>I want to do following task by using c#.
>
> Run -   regedit
> Navigate path -
> HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY
> Rightclick --> new>DWORD>
> add key ExtensionHardening
> value = 0
>
> For that propose i write following code:
>
> RegistryKey regkey;
>        regkey =
> Registry.CurrentUser.OpenSubKey("HKEY_CURRENT_USER\\SOFTWARE\\MICROSOFT\\OFFICE\\12.0\\EXCEL\\SECURITY",
> true);
>
> But i get regkey value is null.
>
> what is wrong in above code.
>
>

Bookmark and Share