How to set the registry key value

I have one Delphi XE2 project to write something in a registry key. Therefore, I defined the following codes:

procedure TMainForm.BitBtn01Click(Sender: TObject); var RegistryEntry: TRegistry; begin RegistryEntry:= TRegistry.Create(KEY_READ); RegistryEntry.RootKey:= HKEY_LOCAL_MACHINE; if (not RegistryEntry.KeyExists('Software\MyCompanyName\MyName\')) then begin RegistryEntry.Access:= KEY_WRITE; RegistryEntry.OpenKey('Software\MyCompanyName\MyName\',True); end; RegistryEntry.CloseKey(); RegistryEntry.Free; end; 

If any addition to the string I defined the following codes:

 if (not RegistryEntry.KeyExists('Licenced To')) then begin RegistryEntry.WriteString('Licenced To', 'MySurname MyFirstName'); end; 

My requirements:

01. Setting the default value as shown: Picture

02. In Win64, the node is created under HKEY_LOCAL_MACHINE \ WOWSys64 \ Software, but not under HKEY_LOCAL_MACHINE \ Software.

+1
source share
1 answer

what is the desired behavior for 32-bit applications.
If you need to write to a 64-bit root, you can use KEY_WOW64_64KEY;
In any case, you will need increased write permissions in HKEY_LOCAL_MACHINE

 RegistryEntry.Access:= KEY_WRITE or KEY_WOW64_64KEY; 
+4
source

All Articles