我想在注册表项上设置下面的权限。但是当它尝试时我得到一个NullReferenceException错误。作为一个新手使这个凝灰岩。抛出权限(一直困惑着我),我很难过。有人能告诉我为什么我得到这个?谢谢。NullReferenceException当试图设置与C#的注册表权限
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);
}
}
}
它无法得到RegistryKey rk –