'Registry key gets pushed to different location in C

I try to install a Chrome extension silently using registry. It does work when I manually push the key to Computer\HKEY_CURRENT_USER\SOFTWARE\Policies\Google\Chrome\ExtensionInstallForcelist key value: gighmmpiobklfepjocnamgkkbiglidom;https://clients2.google.com/service/update2/crx. It's an adblocker.

When I do the same with my C program it doesn't push the new key to the desired location. When I search the whole registry, the key is pushed in a very different place. The key gets pushed to this location in the registry: Computer\HKEY_USERS\S-1-5-21-2801756348-263109946-2004673029-1002\Computer\HKEY_CURRENT_USER\SOFTWARE\Policies\Google\Chrome\ExtensionInstallForcelist.

How can I push my registry key successfully without it being pushed in a different location?

#include <stdio.h>
#include <Windows.h>

int main()
{
    HKEY key;
    int r = RegCreateKeyExA(HKEY_CURRENT_USER, "Computer\\HKEY_CURRENT_USER\\SOFTWARE\\Policies\\Google\\Chrome\\ExtensionInstallForcelist",
                            0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL);
    if (r != ERROR_SUCCESS)
    {
        printf("error\n");
    }

    r = RegSetKeyValueA(key, NULL, "1", REG_SZ, "gighmmpiobklfepjocnamgkkbiglidom;https://clients2.google.com/service/update2/crx", 100);
    if (r != ERROR_SUCCESS)
    {
        printf("error 2\n");
    }

    RegCloseKey(key);
}


Solution 1:[1]

When you create the key, you pass HKEY_CURRENT_USER to the hKey parameter but also put HKEY_CURRENT_USER in the path, which expects a subkey of HKEY_CURRENT_USER. Try using "SOFTWARE\\Policies\\Google\\Chrome\\ExtensionInstallForcelist" instead.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 xnsc