Add registry key using function in innosetup

inno-setup

Solution

That happens because you're assigning the value of your `IsServer` variable only at the wizard form initialization. You'd need to read the actual value ideally from your `InstallAsServer` function, thus you can even remove the `IsServer` variable. You might simplify your code to something like this:

[Registry]
Root: HKLM; Subkey: "Software\company\product\Settings"; ValueType: string; ValueName: "IsServer"; ValueData: {code:InstallAsServer}

[Code]
var
  Page: TInputOptionWizardPage;

procedure InitializeWizard;
begin
  Page := CreateInputOptionPage(wpWelcome, 'Install Type', 'Select Install Type',
    'Please select Installation type; If Server click Server else Client', True, 
    False);

  // add items
  Page.Add('Install as Server');
  Page.Add('Install as Client');

  // set initial values (optional)
  Page.Values[0] := True;
  Page.Values[1] := False;
end;

function InstallAsServer(Value: string): string;
begin
  // read the actual value directly from the Page
  if not Page.Values[0] then
    Result := '0'
  else
    Result := '1';    
end;

Problem

How can i add a registry key in innosetup with a value from a function. I want to set the value of IsServer in registry as the return value of InstallAsServer ``` [Code] [Registry] Root: HKLM; Subkey: "Software\company\product\Settings"; ValueType: string; ValueName: "IsServer"; ValueData: {code:InstallAsServer} var Page: TInputOptionWizardPage; IsServer: Boolean; procedure InitializeWizard; begin Page := CreateInputOptionPage(wpWelcome, 'Install Type', 'Select Install Type', 'Please select Installation type; If Server click Server else Client', True, False); // Add items Page.Add('Install as Server'); Page.Add('Install as Client'); // Set initial values (optional) Page.Values[0] := True; Page.Values[1] := False; IsServer := Page.Values[0]; end; function InstallAsServer(emppararm: string): string; //emppararm not used just for syntax begin if (IsServer=False) then begin result:= '0'; end else begin result:= '1'; end end; ``` But i always get the value set as 1 even if i select server or client in the page

Original source