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 :
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?
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.
Follow the following code, note the optional true argument:
true
RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\Tomcat7",true); key.SetValue("Start", 2, RegistryValueKind.DWord);