The registry APIs are providing erroneous results.

Why is the number of subkeys zero?

#include <iostream>

#include <windows.h>

#include <winreg.h>

using namespace std;

int main (int number_of_arguments, char* arguments[]) {

HKEY handle;

DWORD number_of_subkeys;

LSTATUS result = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
0, KEY_QUERY_VALUE, &handle);

if (result != 0) {

cout << "Failed to open registry key: " << result;

}

result = RegQueryInfoKeyA (handle,
NULL, NULL, NULL, &number_of_subkeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

if (result != 0) {

cout << "Failed to read registry key: " << result;

}

else if (result == 0) {


cout << "Number of subkeys: " << number_of_subkeys;

}

while (1 == 1) {
}

}
On my machine number of sub keys is 1.
Maybe use regedit and check the registry
One thing to keep in mind is that 64-bit Windows redirects some registry keys when the process is 32-bit. For example, attempts to open HKEY_LOCAL_MACHINE\Software\* from a 32-bit process will be redirected to HKEY_LOCAL_MACHINE\Software\Wow6432Node\*.
To disable the redirection, OR KEY_WOW64_64KEY to the samDesired parameter.

See:
https://docs.microsoft.com/en-us/windows/desktop/api/winreg/nf-winreg-regopenkeyexa
https://docs.microsoft.com/en-us/windows/desktop/SysInfo/registry-key-security-and-access-rights
Registered users can post here. Sign in or register to post.