|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
c# cannot change registry valuevalue 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? 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 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. "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); 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. > >
Other interesting topics
Does C# have static local variables like C++?
trouble with connection to a db Serializing objects into application settings Overriding the add method of a generic dictionary Beginner Question - Application Design Trying to Create a Test Class for System.Data.SqlClient Incremental increase in setup size Do local references destruct on method exit? "Logon failure" using Invoke("SetPassword"... How do a loop this program? Learning CSharp |
|||||||||||||||||||||||