The registry is like a file system with different access rights for the different keys. Navigate to your key using regedit and open the 'Permissions' command from the context menu to see the permissions for specific users and groups. Some keys have restricted access even for administrators (SAM, SECURITY). Such keys can be only accessed by the SYSTEM user.
So the answer to your question is: You must have the access rights which are usually granted when you open the key using the account of the key's owner.
At the moment I know only two reasons for denied permissions when trying to write to HKCU:
Using RegOpenKeyEx(), the key was not opened with the KEY_SET_VALUE or KEY_WRITE access right.
Using RegOpenKey() instead of RegOpenKeyEx().
Regarding the second reason I will cite the MSDN:
The RegOpenKey function uses the default security access mask to open a key. If opening the key requires a different access right, the function fails, returning ERROR_ACCESS_DENIED. An application should use the RegOpenKeyEx function to specify an access mask in this situation.
If this does not solve your problem, you should show us the code that fails (including the RegOpenKeyEx() call).
Last Visit: 31-Dec-99 18:00 Last Update: 19-Sep-14 9:03