Why I cannot create a sub key under HKEY_USERS in the Windows registry? RRS feed

  • Question

  • Hi,

    I want to create a subkey under the HKEYS_USERS registry key. But I when I do it in the RegEditor, got a "Cannot create key" error message. If I do it programmatically, I got an "Incorrect parameter" error.

    I wonder why I cannot create a subkey there. I am already the Administrator of the machine.

    Regards, David Shen

    Wednesday, September 5, 2018 9:07 AM

All replies

  • Why do you want to create a key here ?

    See MSDN :

    "An application cannot create a key that is a direct child of HKEY_USERS or HKEY_LOCAL_MACHINE. An application can create subkeys in lower levels of the HKEY_USERS or HKEY_LOCAL_MACHINE trees."

    Wednesday, September 5, 2018 11:11 AM
  • It makes sense if you think about it.

    Key roots such as HKLM and HKEY_USERS are kind of virtual keys, and all immediate subkeys of these root keys have their individual files containing themselves and the keys they contains.

    Since RegCreateSubEx() do not have parameter for you to specify which file path you want to store the keys, the registry would not have idea on where to store it.

    To "create" subkey under these two places you need to call RegLoadKey() API, which does allow you to specify where the registry data would be stored. (You create the key content elsewhere, then call RegSaveKeyEx() to save to file to be loaded later)

    Thursday, September 6, 2018 2:12 AM
  • Yeah...I wish I know why I am asked to do so!!!

    Regards, David Shen

    Thursday, September 6, 2018 3:45 AM
  • Hi cheong00,

    Would subkeys create in this way behavior as normal subkeys created by Windows system? Suppose I created a subkey for user A, and later user A really logged onto that machine, what would happen to the subkeys I created for that user before?



    Regards, David Shen

    Thursday, September 6, 2018 3:55 AM
  • The keys loaded with RegLoadKey() are not persistant (I mean the setting to load the key file is not persistant, the key contents are stored in the file when the registry is unloaded or system is shutdown). You need to load it each time the system is restarted (you can write an Automatic start Windows service to do so, or check to see if the key hive is loaded when your program starts, then load if the key hive is not loaded).
    Thursday, September 6, 2018 6:05 AM