C # Set Registry Value throws UnauthorizedAccessException

I have a C # application and I'm trying to edit a service through the registry. I am using a manifest file that requires administrator privileges to run my application. Despite this, this code raises a System.UnauthorizedAccessException: Cannot write to the registry key :

 RegistryKey key = Registry.LocalMachine.OpenSubKey ("SYSTEM\\CurrentControlSet\\services\\Tomcat7"); key.SetValue ("Start", 2, RegistryValueKind.DWord); 

Does anyone have any ideas how to fix this?

+12
c #
source share
2 answers

This can help,

Link to a similar stack overflow problem

it looks like you are opening the key for read only ... Google is your friend.

+5
source share

Follow the following code, note the optional true argument:

 RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\Tomcat7",true); key.SetValue("Start", 2, RegistryValueKind.DWord); 
+22
source share

All Articles