RegCreateEx return 5 Access Denied on Windows 7
I have one program that uses API RegCreateKeyEx and that works perfectly fine on WinXP and Vista.
Program is generally launched in elevated privileges开发者_JAVA技巧 . When I try to use same program in Windows 7 , RegCreateKeyEx API is returning 5 (access denied).
Any idea how to resolve this?
This error occurs when you're trying to create a key in a portion of the registry where you don't have write access. On Windows 7, this is basically everywhere.
To increase compatibility of 32 bit applications between XP/7 it's suggested you create the key in the 32 bit view of the registry. Modify your call to include the mask KEY_WOW64_32KEY
so it uses the 32 bit view:
result = RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Foo"),
NULL, NULL, NULL, KEY_ALL_ACCESS | KEY_WOW64_32KEY, NULL, &hkey, &disposition);
Then create the key first in the registry manually under HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Foo
. Edit the permissions and give yourself (or everyone) Full Control.
You should now be able to access the key from a 32 bit application.
精彩评论