开发者

C# 32bit app 64bit registry

I know there are lots of sites about this. I've been testing out different ideas for about 6 hours now. I'm trying to get a 32bit app to modify the 64bit registry. I need to set the permissions to HKLM\Software\Microsoft\Windows\Current Version\Installer\UserData\ If you are wondering why, it's because our software throws an error if the permissions aren't correct.

Here is what I'm trying

static bool SetRegistryPermissions(string hkLmKey, string userAccount)
        {
            //this will force the app to see the 64bit registry 开发者_StackOverflow社区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); 

The program was working fine on a test key in WoW6432Node prior to changing the key to localMachineX64. Now I get a security exception when debugging on the OpenSubKey.

Any advice is welcome and Thanks for your time.

P.S. Any suggestions for books that contain good info writing NT permissions in C# would be a bonus.


Could you create a small 64 bit application that could set the 64 bit permissions? You could then call the exe from your installer's post install event.


I'm unsure if there is a .NET approach to this, but the Windows API definitely provides a solution. You can use the RegOpenKeyEx function with KEY_WOW64_64KEY (http://msdn.microsoft.com/en-us/library/ms724878%28v=vs.85%29.aspx) included as one of the access options. This will allow your 32 bit app to access the full registry, not just the Wow6432Node sandbox.

Edit: pinvoke.net has a C# example ready to go: http://www.pinvoke.net/default.aspx/advapi32/RegOpenKeyEx.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜