WindowsRegistry setValue issue

The getValue works just fine for a String value, but all attempts to set the same key returns false and no changes are made. Is there something silly I might have overlooked that could cause this? The ‘From’ and ‘To’ keys exist.

using namespace std;
#include <JuceHeader.h>

int main (int argc, char* argv)
String key1;
String key2;
String key3;
String var;
String val;
String def;
bool OK1;
bool OK2;
bool OK3;
uint32 iVal;

iVal = 1234;
def = "asdfg";
var = "2020-10-06";
key1 = "HKEY_LOCAL_MACHINE\\SOFTWARE\\SmallSystemSoftware\\GolfersData\\From";
key2 = "HKEY_LOCAL_MACHINE\\SOFTWARE\\SmallSystemSoftware\\GolfersData\\To";
key3 = "HKEY_LOCAL_MACHINE\\SOFTWARE\\SmallSystemSoftware\\GolfersData\\House";

val = WindowsRegistry::getValue(key1, def);
OK1 = WindowsRegistry::setValue(key1, var);
OK2 = WindowsRegistry::setValue(key2, var);
OK3 = WindowsRegistry::setValue(key3, iVal);
cout << "Value read " << val << "\n";
cout << "setValue1 reply " << (int) OK1 << "\n";
cout << "setValue2 reply " << (int) OK2 << "\n";
cout << "setValue3 reply " << (int) OK3 << "\n";
return 0;


Further investigation revealed that the call to RegCreateKeyEx was returning 5 (invalid key). Switching to HKEY_CURRENT_USER from HKEY_LOCAL_MACHINE solved the issue.