I have a C# application and I am trying to edit a service through the registry. I am using a manifest file that requires administrator privileges to run my application. Despite that, this code throws
System.UnauthorizedAccessException: Cannot write to the registry key.
RegistryKey key = Registry.LocalMachine.OpenSubKey ("SYSTEM\\CurrentControlSet\\services\\Tomcat7");
key.SetValue ("Start", 2, RegistryValueKind.DWord);
Does anybody have any ideas for how to fix this?
Follow the following code, note the additional true
argument:
RegistryKey key = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\Tomcat7",true);
key.SetValue("Start", 2, RegistryValueKind.DWord);
This might help ,
Link to similar issue on stack overflow
looks like you are opening the key read only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With