2

我无法枚举 HKEY_LOCAL_MACHINE\SOFTWARE 的子键,我只能得到 HKEY_LOCAL_MACHINE 上的子键。

WCHAR Temp[255];
DWORD TMP = 255;
HKEY hKey;
int count = 0;
long regError;

...

regError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\", NULL, KEY_ENUMERATE_SUB_KEYS, &hKey);
if (regError == ERROR_SUCCESS){
    file<<"Key opened!\nSubkeys of HKEY_LOCAL_MACHINE\\SOFTWARE:\n\n";
    while ((regError = RegEnumKeyEx(HKEY_LOCAL_MACHINE, count, Temp, &TMP, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS){
        TMP = sizeof (Temp);
        count++;
        file<<count<<". "<<Temp<<std::endl;
    }
    if (regError == ERROR_NO_MORE_ITEMS) file<<"Done.";
    else file << std::endl <<"RegEnumKeyEx error!";
}
else file << std::endl <<"RegOpenKeyEx error!";

RegCloseKey(hKey);

这是我的文件:

Key opened!
Subkeys of HKEY_LOCAL_MACHINE\SOFTWARE:

1. BCD00000000
2. DRIVERS
3. HARDWARE
4. SAM
5. SECURITY
6. SOFTWARE
7. SYSTEM
Done.

如何在 HKEY_LOCAL_MACHINE\SOFTWARE 而不仅仅是 HKLM 中输出密钥?谢谢。

4

1 回答 1

3

您将错误传递HKEYRegEnumKeyEx(). 您正在传递HKLM根,但您需要传递HKEY返回RegOpenKeyEx()的。换句话说,改变这个:

RegEnumKeyEx(HKEY_LOCAL_MACHINE, ...)

对此:

RegEnumKeyEx(hKey, ...)
于 2013-10-01T18:08:52.063 回答