I'm developing an application that needs to write to the registry. It works fine on XP, but when I run it on Vista, from Visual Studio, I get a security exception in:
Registry.LocalMachine.OpenSubKey("SOFTWARE", true);
I'm trying to write a new key into that branch of the registry.
What's the right way to do this, firstly so that I can run my application from VS on Vista, and secondly so that my users don't run into problems running on Vista.
Thanks...
On both XP and Vista you need Admin rights to write a new key under LocalMachine.
You'll be finding this works on XP and fails on Vista due to different account defaults.
The quick and dirty solution is to ensure your application runs with Admin rights in both cases, though in on Vista this tends to be frowned upon.
The better solution would be to redesign things slightly - can the new sub key be written by your installer (which runs with Admin rights), or could you store your information somewhere else?
Standard users, and admin's running with UAC on Vista, do not have permission to write the the local machine registry key. This would fail on XP too if you ran as standard user.
Your options are:
You can only write to that key if you're running as administrator. So you'll need to run VS as administrator and your users will need to run the application as administrator.
My suggestion would be to see if you really need to write to LocalMachine. You can write to CurrentUser without admin rights.
I assume it "works under XP" because everybody runs it as Admin under XP?
You will could try to circumvent (create the key during Setup or use a key under CurrrentUser or something).
You could grant the privilege to your Application during Setup. I'm afraid I'm a little short on details on how to do that.
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