I am trying to write new key i.e Mode and assign a a value to it, my system is 32 bit and code is as follows. I am getting an error with the following code as failed to set data for Mode I have tried with all rectification by setting different parameters to reg.Access but no success. I always have to keep reg.Access to KEY_READ as with KEY_WRITE it will not open subkey at reg.OpenKey method.
reg := TRegistry.Create(KEY_READ);
reg.RootKey := HKEY_LOCAL_MACHINE;
if (not reg.KeyExists('\Software\MyApp\appname\')) then
begin
MessageDlg('Key not found! Created now.', mtInformation, mbOKCancel, 0);
end;
reg.Access:= KEY_READ;
openResult := reg.OpenKey('\Software\MyApp\appname\',True);
if not openResult = True then
begin
MessageDlg('Unable to create key! Exiting.', mtError, mbOKCancel, 0);
Exit();
end;
if not reg.KeyExists('Mode') then
begin
reg.WriteString('Mode','trial');
end;