在 Inno Setup 中如何将用户输入保存到注册表?

In Inno Setup how to save user inputs to registry?

这就是我想要弄清楚的,在 Inno Setup 中我希望安装程序获得

  1. 用户名(手动输入)
  2. 生日(手动输入)

我想将这两个用作变量以将其保存在注册表中

只需结合这些问题的答案:

  • Adding user completed form to Inno Setup
  • or Inno Setup: How to pass variable from [Code] to [Run]

他们向您展示了如何使用 CreateInputQueryPage function and scripted constants 获得这样的代码:

[Registry]
Root: HKCU; Subkey: "Software\My Company\My Program"; \
    ValueType: string; ValueName: "UserName"; ValueData: "{code:GetUserName}"
Root: HKCU; Subkey: "Software\My Company\My Program"; \
    ValueType: string; ValueName: "UserBirthday"; ValueData: "{code:GetUserBirthday}"
[Code]

var
  UserInputsPage: TInputQueryWizardPage;

function GetUserName(Param: string): string;
begin
  Result := UserInputsPage.Values[0];
end;

function GetUserBirthday(Param: string): string;
begin
  Result := UserInputsPage.Values[1];
end;

procedure InitializeWizard;
begin
  { Create the page }
  UserInputsPage :=
    CreateInputQueryPage(wpWelcome,
      'User information', 'User name and birthday',
      'Please specify the following information, then click Next.');
  UserInputsPage.Add('Name:', False);
  UserInputsPage.Add('Birthday:', False);
end;

这将创建一个注册表项,例如:

[HKEY_CURRENT_USER\SOFTWARE\My Company\My Program]
"UserName"="John Doe"
"UserBirthday"="1975-05-02"