C# 注册表安全设置

C# 注册表安全设置,c#,.net,registry,C#,.net,Registry,我试图访问注册表的某个部分,但是当我试图打开它时,它总是返回null 但是,我知道位置是正确的,因为我可以在reedit中导航到它 这是我尝试访问它的代码行 Microsoft.Win32.RegistryKey RK = Microsoft.Win32.Registry.LocalMachine.OpenSubK("Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData", false); 有人有什么想法吗 更新 看

我试图访问注册表的某个部分,但是当我试图打开它时,它总是返回null

但是,我知道位置是正确的,因为我可以在reedit中导航到它

这是我尝试访问它的代码行

Microsoft.Win32.RegistryKey RK = Microsoft.Win32.Registry.LocalMachine.OpenSubK("Software\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData", false);
有人有什么想法吗

更新

看起来我看到了一个不同版本的注册表,这需要是一个32位的应用程序,但它需要能够看到32位和64位版本的注册表


谢谢

您是否通过属性
[System.Security.permissions.SecurityPermission(System.Security.permissions.SecurityAction.LinkDemand,Flags=System.Security.permissions.SecurityPermissionFlag.RegistryPermission)]应用权限访问注册表项
或者您是否以管理员身份运行该程序?以下是根据的安全权限的详细信息,更恰当地说,您是否通过属性[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.LinkDemand,Flags=System.Security.Permissions.SecurityPermissionFlag.RegistryPermission)]应用权限访问注册表项或者您是否以管理员身份运行该程序?这里详细介绍了安全权限,更贴切地说,您的应用程序是如何运行的?换句话说,您的应用程序在什么上下文下运行?它是通过双击.exe来运行的,还是安装程序正在启动该进程?安装程序应用程序在与预期不同的上下文中运行

您的应用程序是如何运行的?换句话说,您的应用程序在什么上下文下运行?它是通过双击.exe来运行的,还是安装程序正在启动该进程?安装程序应用程序在与预期不同的上下文中运行

 var tempKey = Registry.LocalMachine;
和安全访问

var rule = new RegistryAccessRule(LOGON_USER_NAME, RegistryRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow);
var security = new RegistrySecurity();
security.AddAccessRule(rule);
tempKey.SetAccessControl(security);

 tempKey = tempkey.OpenSubKey(SUB_KEY, RegistryKeyPermissionCheck.ReadWriteSubTree);
和用于登录\u用户名\u

(一)

(二)

和安全访问

var rule = new RegistryAccessRule(LOGON_USER_NAME, RegistryRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow);
var security = new RegistrySecurity();
security.AddAccessRule(rule);
tempKey.SetAccessControl(security);

 tempKey = tempkey.OpenSubKey(SUB_KEY, RegistryKeyPermissionCheck.ReadWriteSubTree);
和用于登录\u用户名\u

(一)

(二)


您可能会看到注册表的不同版本,这取决于您是否运行x86或x64代码,我认为还取决于您的权限。您可能会看到注册表的不同版本,这取决于您是否运行x86或x64代码,我认为还取决于您的权限。它作为windows服务运行它作为windows服务运行
var LOGON_USER_NAME = System.Security.Principal.WindowsIdentity.GetCurrent().Name;