Rubi Halder
Rubi Halder

Reputation: 593

How to set value of Registry Key

I am having one Delphi XE2 project to write something in registry key. So I have 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 string addition I have 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 OS the node is created under HKEY_LOCAL_MACHINE\WOWSys64\Software but not under HKEY_LOCAL_MACHINE\Software.

Upvotes: 3

Views: 7388

Answers (1)

bummi
bummi

Reputation: 27384

that desired behavoir for 32-Bit applications.
If you need to write to 64-Bit root you can use KEY_WOW64_64KEY;
In any case you will need elevated rights for writung to HKEY_LOCAL_MACHINE

RegistryEntry.Access:= KEY_WRITE or KEY_WOW64_64KEY;

Upvotes: 7

Related Questions