3
votes

The straight WIN32API program I'm writing (no MFC, no .NET) uses the registry. Should a registry error occur, I'd like to print the full path of the key that failed.

HKEY_CLASSES_ROOT, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, and HKEY_USERS are HKEY (DWORD) values (0x8000000 for HKEY_CLASSES_ROOT), etc. The subkey is a LPCTSTR, as is the value name.

Is there a method to convert the HKEY, subkey and value name (including any redirection (http://msdn.microsoft.com/en-us/library/windows/desktop/ms724072(v=vs.85).aspx)) to a text string?

I realize I can build a table of the HKEY's myself, and they're unlikely to change, but that's a crass way to do it.

2

2 Answers

3
votes

No such API that I know of. The only registry functions that give you names are RegEnum... functions, which give you names relative to an open key.

There isn't much demand for the reverse direction (HKEY to name), so the registry is probably indexed only in the common direction (name to HKEY).

You will have to keep track of names yourself as you navigate the hierarchy.

3
votes

Probably not worth it but you could use ntdll's NTQueryKey (ZwQueryKey) with KEY_INFORMATION_CLASS.KeyNameInformation to convert a registry handle to a "path" string although you would end up with \REGISTRY\USER instead of HKEY_CURRENT_USER formats.