I am trying to write/update a value in HKLM using TRegistry, but never succeed when I open the registry using OpenKey() (it always returns false).
My application is 32bit. I write the code in C++Builder 10.3. My OS is Windows 10.
Here is my code:
BOOL bIsWow64 = FALSE;
BOOL result=FALSE;
IsWow64Process(GetCurrentProcess(), &bIsWow64);
long flags = KEY_WRITE;
if (bIsWow64) flags |= KEY_WOW64_64KEY;
TRegistry *sfReg = new TRegistry(flags);
sfReg->RootKey = HKEY_LOCAL_MACHINE;
UnicodeString mykey="software\\MyName\\MyAppName\\";
sfReg->Access=flags;
result=sfReg->OpenKey(mykey,true);
if(result)
{
if(MainForm->usermode==USER_TEACHER)
{
sfReg->WriteString("tPswd",Edit2->Text);
}
else
{
sfReg->WriteString("fPswd",Edit2->Text);
}
}
delete sfReg;
p->CommaText=MainForm->pLang->Strings[LANG_START+134];
MessageDlg(p->Strings[1], mtInformation, TMsgDlgButtons() << mbOK, 0);
Close();