Can't write into HKLM Registry

Hello everyone,

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?

Here is my code:
1
2
3
4
5
6
7
8
9
10
DWORD dwDisposition;
    HKEY hKey2;
    RegCreateKeyEx(HKEY_LOCAL_MACHINE,
                   "dini mueter",
				   0,
				   NULL,
				   REG_OPTION_NON_VOLATILE,
				   KEY_WRITE,NULL, &hKey2, &dwDisposition);
    if (dwDisposition != REG_CREATED_NEW_KEY && dwDisposition != REG_OPENED_EXISTING_KEY)
        MessageBox(0,"The function failed","Error",0);


Greets, theRunner

PS.: Ah and I forgot to mention: Amazingly, even when I execute the exe-file with admin rights in the windows explorer, I get the same error message.
Last edited on
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.
Topic archived. No new replies allowed.