C#32位应用64位注册表

时间:2011-01-10 00:04:30

标签: c# permissions registry redirect

我知道有很多关于此的网站。我现在已经测试了大约6个小时的不同想法。我正在尝试使用32位应用程序来修改64位注册表。我需要将权限设置为HKLM \ Software \ Microsoft \ Windows \ Current Version \ Installer \ UserData \如果您想知道原因,那是因为如果权限不正确,我们的软件会抛出错误。

这是我正在尝试的

static bool SetRegistryPermissions(string hkLmKey, string userAccount)
        {
            //this will force the app to see the 64bit registry instead of being redirected
            RegistryKey localMachineX64View = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
            RegistryKey rk = localMachineX64View.OpenSubKey(hkLmKey, true);

            //This redirects to the Wow6432Node in the registry
            //RegistryKey rk = Registry.LocalMachine.OpenSubKey(hkLmKey, true); 

在将密钥更改为localMachineX64之前,该程序在WoW6432Node中的测试密钥上工作正常。现在,我在OpenSubKey上调试时遇到安全异常。

欢迎任何建议,感谢您的时间。

P.S。对于包含在C#中编写NT权限的良好信息的书籍的任何建议都将是一个奖励。

2 个答案:

答案 0 :(得分:0)

你能创建一个可以设置64位权限的小型64位应用程序吗?然后,您可以从安装程序的安装后事件中调用exe。

答案 1 :(得分:0)

我不确定是否有.NET方法,但Windows API肯定提供了解决方案。您可以使用包含KEY_WOW64_64KEY(http://msdn.microsoft.com/en-us/library/ms724878%28v=vs.85%29.aspx)的RegOpenKeyEx函数作为访问选项之一。这将允许您的32位应用程序访问完整的注册表,而不仅仅是Wow6432Node沙箱。

编辑:pinvoke.net准备好了一个C#示例:http://www.pinvoke.net/default.aspx/advapi32/RegOpenKeyEx.html

相关问题