I’m creating a registry key like this:
Key = Registry.CurrentUser.CreateSubKey("Mykey");
Then open it when my application runs the second time:
Key = Registry.CurrentUser.OpenSubKey("Mykey");
But I got an access denied when trying to create its subkey:
Subkey = Key.CreateSubKey("Mysubkey"); <-- Runtime error here
Any suggestion why? I guess it’s because I didn’t set the permissions on ‘Mykey’ at the time it is created. But I just don’t know how to set these permissions.
You can set your app to run on full trust in your project properties, also, you can have your assemblies signed with a key from the “Signing” tab on the project properties page. Finally, run your app as an administrator and set it to run on admin mode by right clicking on the app launch icon and going into Compatibility tab and checking the “Run this program as an Administrator” checkbox. Registry handling requires full trust on the app to run properly. Hope this helps.
EDIT: Or alternatively, as people have mentioned, use local settings.