I'm trying to create a key in HKEY_LOCAL_MACHINE - without success: I get the messagebox "The function failed". This means that the If-condition is met (see the code below).
When I try the same thing with HKEY_CURRENT_USER, the key is created without any problem. So I suppose the problem is that I don't have enough privileges (since HKLM needs admin privileges).
I am using Code Blocks. Is there a way to set the privileges appropriately?
By now I solved the problem. In fact I wanted to create a Key under HKEY_CLASSES_ROOT\\\\Folder\\\\shell\\\\Myapplication
To add a new entry to the context menu when clicking the right mouse button on a folder in the windows explorer.
This worked fine when running the exe as administrator.
Apparently certain regions of the Windows Registry are permanently blocked (like HKEY_LOCAL_MACHINE\\\\Myapplication: the creation of this key will be blocked by Windows).
Résumé: Windows seems to block certain regions of its Registry to prevent an application from dammaging gravely the Windows Core. Even if you run the exe as administrator you can't modify the Registry in these regions.