Problem with NKRegCreateKeyEx() and HKEY_CURRENT_USER / WEC2013 RRS feed

  • Question

  • Hello all,

    I have problems initializing registry entries under the HKEY_CURRENT_USER subtree through the IOCTL_HAL_INITREGISTRY!

    All runs well when registry entries values are targeted to HKEY_LOCAL_MACHINE, but when target is HKEY_CURRENT_USER the entries do not show in the OS after startup.

    Inititializing is done like in the following sample:

    BOOL OALIoCtlHalInitRegistry(
        UINT32 code, 
        VOID *pInBuffer,
        UINT32 inSize, 
        VOID *pOutBuffer, 
        UINT32 outSize, 
        UINT32 *pOutSize
        static const WCHAR KEYNAME[] = L"Software\\TestKey";
        static const WCHAR VALUENAME[] = L"TestValue";
        WCHAR value[] = L"Success";
        BOOL rc;
        HKEY hKey;
        DWORD dwDisposition;
        OALMSG(1, (L"OALIoCtlHalInitRegistry()+ write to HKCU\r\n"));
        rc = NKRegCreateKeyEx(HKEY_CURRENT_USER, KEYNAME, 0, NULL, 0, 0, NULL, &hKey, &dwDisposition);
        switch (dwDisposition)
        case REG_CREATED_NEW_KEY:
            OALMSG(1, (L"REG_CREATED_NEW_KEY\r\n"));
            OALMSG(1, (L"REG_OPENED_EXISTING_KEY\r\n"));
            OALMSG(1, (L"fail\r\n"));
        rc = NKRegSetValueEx(hKey, VALUENAME, 0, REG_SZ, (BYTE *)value, sizeof(value));
        rc = NKRegCloseKey(hKey);
        OALMSG(1, (L"OALIoCtlHalInitRegistry()-\r\n"));
        return TRUE;

    The functions is executed without error, but the registry changes do not show up after the system has booted. With Windows CE 6 the same code does work well. As said, this problem only happens with the HKEY_CURRENT_USER section. Same example with HKEY_LOCAL_MACHINE does function well.

    OS: Windows Embedded Compact 2013 with updates until April 2015

    We are using RAM-ROM filesystem and RAM based registry:



    Any help is apreciated!

    Bernd Kösters METRIC mobile solutions AG

    Tuesday, July 7, 2015 8:52 AM

All replies

  • Who is the current user at that early point?  I think that it is just too early to modify HKCU.

    Bruce Eitman (eMVP) Senior Engineer Bruce.Eitman AT Eurotech DOT com My BLOG Eurotech Inc.

    Tuesday, July 7, 2015 12:30 PM
  • Hello Bruce!

    I am not aware of, that there are different users within Windows Compact at all! However, you are right. It looks like the values are written somewhere but not to the right location. Does Compact have the concept of users and can I switch to a different user to look at the other HKCU?

    Bernd Kösters METRIC mobile solutions AG

    Tuesday, July 7, 2015 12:56 PM
  • Hello Bernd,

    I think Bruce is suggesting you modify the registry later in the boot process.

    Also, is this area protected? In WM you would get an exception if you did not have rights (See



    Tuesday, July 7, 2015 11:16 PM
  • Yes, may be it will be possible to circumvent this problem ("Don't use it" solution).


    The behavior is different than in previous WinCE versions (I don't now Embedded Compact 7 but for CE4.2 / 5 / 6 I know, this is working).

    Within the documentation there is no hint, that it might not work with HKEY_CURRENT_USER. HKEY_CURRENT_USER is listed as valid input parameter for NKRegCreateKeyExW().

    Bernd Kösters METRIC mobile solutions AG

    Thursday, July 9, 2015 7:28 AM
  • Hi Bernt,

    The suggestion is to implement this code later in the boot process, not "Don't use it".

    There may be a security difference in Compact 7 vs the prior versions.


    IoT Girl

    Thursday, July 9, 2015 6:31 PM