473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

c# cannot change registry value

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.ThrowUnauthorizedAccessExceptio n(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?
Feb 21 '07 #1
4 31181
To change the value you should be using CreateSubey instead of OpenSubKey

Eric Renken

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:E3**********************************@microsof t.com...
>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.ThrowUnauthorizedAccessExceptio n(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?

Feb 21 '07 #2

"Eric Renken" <Er********@newsgroup.nospamwrote in message
news:O5**************@TK2MSFTNGP03.phx.gbl...
To change the value you should be using CreateSubey instead of OpenSubKey
Or at least use the OpenSubKey overload that allows you to request write
access.

http://msdn2.microsoft.com/en-us/library/ms128501.aspx
>
Eric Renken

"Chris" <Ch***@discussions.microsoft.comwrote in message
news:E3**********************************@microsof t.com...
>>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.ThrowUnauthorizedAccessExcepti on(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?


Feb 21 '07 #3
"Chris" <Ch***@discussions.microsoft.comwrote in message
news:E3**********************************@microsof t.com...
>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.ThrowUnauthorizedAccessExceptio n(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?

.......OpenSubKey("Software\\My_app", true);

Willy.
Feb 22 '07 #4
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
Feb 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: firenet | last post by:
Came in one morning and found that the following message appeared only on running Access 2000, then the program shuts down, all other office 2000 applications work fine. "Required registry...
6
by: Yogi_Bear_79 | last post by:
I'm Creating new Keys in the registry, but when I do, they always have a Vaule called (Default) type RG_SZ. I need them to be DWord dword:00000005 Is there a way to automaticaly make the...
3
by: caldera | last post by:
Hi, I write a windows service. In that service I create a new subkey for registry. But service install is call CreateSubKey() the program throw an exception to the event log said that Cannot write...
0
by: ahaupt | last post by:
Hi all, I've created a setup project for my app in VS2003 and need to set up some registry values and keys. It is easy enough to just create static keys with static values, but I'd like the...
1
by: scorpion53061 | last post by:
Trying to change a value named in a remote registry. In this case we want to set the password protect function of the screensaver so WMI can do a reboot of the system. (IsSecure or...
2
by: nikou_70 | last post by:
I have a message in (LegalNoticeText) in winlogin in registry ,when user( in our network) log to windows can see massage that I put in LegalNoticeText , every day I should change this message(it's...
0
by: Patrick F | last post by:
I keep getting this error message and i don't know whats the problem is and how to solve it. I have a webproject with 2 components (dll) added to it. One is called PhotoGallery and one is called...
1
by: Patrick F | last post by:
I keep getting this error message and i don't know whats the problem is and how to solve it. I have a webproject with 2 components (dll) added to it. One is called PhotoGallery and one is called...
4
by: CDMAPoster | last post by:
In: http://groups.google.com/group/comp.databases.ms-access/msg/f06bd4c45037ef29 Lyle wrote: :Terry Kreft wrote: : :>Suck it and See? :
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.