I'm trying to set the below permissions on a registry key. But I get a NullReferenceException error when it tries. Being a novice makes this tuff. Throw in permissions (which have always confused me) and I'm stumped. Can someone tell me why I'm getting this? Thanks.
using System;
using Microsoft.Win32;
using System.Security.AccessControl;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
RegistrySecurity rs = new RegistrySecurity();
string user = "Everyone";
RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"\SOFTWARE\Wow6432Node\123Test", true);
rs.AddAccessRule(new RegistryAccessRule(user,
RegistryRights.FullControl | RegistryRights.TakeOwnership,
InheritanceFlags.ContainerInherit,
PropagationFlags.None,
AccessControlType.Allow));
rk.SetAccessControl(rs);
}
}
}