0
votes

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 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.

2
Are you aware that this is the wrong solution to your problem? Standard user should not be writing to HKLM.David Heffernan
If this is the "wrong" solution, how would you correct this issue? I'm ONLY using it when an issue comes up to correct it and prevent the user from having to do it.John Andrews

2 Answers

0
votes

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.

0
votes

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