I want to get all the CLSIDs keys that are under the HKEY_CLASSES_ROOT\\SOFTWARE\\Classes\\CLSID key.

I know that that key is mirror for merged HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\CLSID and HKEY_CURRENT_USER\\SOFTWARE\\Classes\\CLSID keys.

So far I can enumerate all HKEY_CLASSES_ROOT\\SOFTWARE\\Classes\\CLSID (HKEY_LOCAL_MACHINE\\... and HKEY_CURRENT_USER\\... as well) and get that key's names into std::wstring[]. But when I try to open that keys:

//CLSID = e.g. L"{CAFEEFAC-0013-0001-0001-ABCDEFFEDCBB}"
firstKey = HKEY_LOCAL_MACHINE;
keysPath = L"\\SOFTWARE\\Classes\\CLSID\\"+CLSID;
if(x64System)
    regsam = KEY_ALL_ACCESS|KEY_WOW64_64KEY; //on my system
else
    regsam = KEY_ALL_ACCESS;

result = RegOpenKeyEx(firstKey, keysPath.c_str(), 0, regsam, &outputKey);

It works only for HKEY_CURRENT_USER, for HKEY_LOCAL_MACHINE it returns ERROR_ACCESS_DENIED. Even when I run my program as administrator (in regedit.exe I can see that key's name is good, if it wouldn't error message would be not found, not ERROR_ACCESS_DENIED anyway).

So what should I do to access that keys? I'm sure that some programs can access that keys. Or at least how to get their default value (it is all I want from them)?

In my program I can only list their names with RegQueryInfoKey but cannot access them with RegOpenKeyEx.

有帮助吗?

解决方案

Even as an admin you don't have KEY_ALL_ACCESS on HKLM when UAC is enabled. If you want or need KEY_ALL_ACCESS you Need to run your program elevated.

Reduce your rights to the needed Level. If you only want to read just use KEY_READ!

And take care that you have an embedded manifest, without a manifest you might get access, but tis access is virtualized and you don't get access to the real key.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top