I am getting error cannot write to the registry key when i am trying to save my keys in the registry .
//Here is my code .
Note : I tried to run as an Admin
try this......someone may find useful....
using System.Security;
using System.Security.AccessControl;
using Microsoft.Win32;
string user = Environment.UserDomainName + "\\" + Environment.UserName;
RegistryKey rk =
RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).
OpenSubKey("SOFTWARE",true);
RegistrySecurity rs = new RegistrySecurity();
rs.AddAccessRule(new RegistryAccessRule(user,
RegistryRights.WriteKey | RegistryRights.ReadKey | RegistryRights.Delete,
InheritanceFlags.None,
PropagationFlags.None,
AccessControlType.Allow));
rk = Registry.CurrentUser.CreateSubKey("RegistryRightsExample",
RegistryKeyPermissionCheck.Default, rs);
if (null == skms)
{
skms = Registry.LocalMachine.OpenSubKey("SOFTWARE",true);
RegistryKey key = skms.CreateSubKey(
RegistryKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree);
}
This is the answer for my question .
Try this:
RegistryKey skms = SoftwareKey.OpenSubKey(RegistryKeyName, true);
The second parameter should be set to true if you need write access to the key.
-EDIT-
On 64-bit system, you can try this (if you are using .Net 4):
private readonly RegistryKey SoftwareKey =
RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).
OpenSubKey("SOFTWARE");
You are probably falling foul of registry redirection. Perhaps you have a 32 bit process on a 64 bit system and writes to HKLM\Software get redirected to HKLM\Software\Wow6432Node.
You need to open the 64 bit key directly, or compile for AnyCPU.