How to set value of Registry Key

☆樱花仙子☆ 提交于 2019-12-11 07:35:49

问题


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 :

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


回答1:


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;


来源:https://stackoverflow.com/questions/16144046/how-to-set-value-of-registry-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!