I am attempting to write a function that checks the registry value to see if color is enabled for the console on windows.
Computer\HKEY_CURRENT_USER\Console\VirtualTerminalLevel
If you navigate to here through the registry, this is the value i need to retrieve. It is either 1 or 0, 1 being enabled 0 being disabled.
#include <Windows.h>
DWORD val;
DWORD dataSize = sizeof(val);
if (ERROR_SUCCESS == RegGetValueA(HKEY_LOCAL_MACHINE, "Computer\\HKEY_CURRENT_USER\\Console", "VirtualTerminalLevel", RRF_RT_DWORD, nullptr, &val, &dataSize)) {
printf("Value is %i\n", val);
}
else {
printf("Error reading.\n");
}
This is my attempt. This always results in "error reading". My question is, What do i need to place in "subkey" and "value" args of the RegGetValueA function?
You are specifying the wrong path to the value. Do not include Computer\HKEY_CURRENT_USER
in the lpSubKey
parameter. That is only for human readability, not actually part of the path for the Registry API to use. The lpSubKey
value is relative to the hKey
root, which in this case should be HKEY_CURRENT_USER
, not HKEY_LOCAL_MACHINE
.
Try this instead:
#include <Windows.h>
DWORD val;
DWORD dataSize = sizeof(val);
if (ERROR_SUCCESS == RegGetValueA(HKEY_CURRENT_USER, "Console", "VirtualTerminalLevel", RRF_RT_DWORD, nullptr, &val, &dataSize)) {
printf("Value is %u”, val);
}
else {
printf("Error reading.\n");
}