在 Inno Setup 中将输入的文本保存到 TXT 文件

fur*_*kac 2 inno-setup pascalscript

我必须将用户键入的用户名和密码保存到文本文件中,但它会在用户键入之前创建文本文件并保存文本。(因此创建了空文本文件)。

我想我必须对程序做一些事情,但是虽然我搜索了解决方案,但我找不到。

我的代码:

[Code]
var
  Page: TInputQueryWizardPage;
  username: String;
  password: String;

procedure InitializeWizard;
begin
  { Create the page }
  Page := CreateInputQueryPage(wpWelcome,
    'Username & Password', 'Username like : e201600',
    'Please enter your username and password.');
  { Add items (False means it's not a password edit) }
  Page.Add('Username:', False);
  Page.Add('Password:', True);
  { Set initial values (optional) }
  Page.Values[0] := ExpandConstant('hello5');
  Page.Values[1] := ExpandConstant('');
  { Read values into variables }
  username := Page.Values[0];
  password := Page.Values[1];
  SaveStringToFile('c:\filename.txt', username+#13#10+password+#13#10, False);
end;
Run Code Online (Sandbox Code Playgroud)

Sla*_*ppy 5

您正在安装程序启动时创建输入页面并立即将字段保存到文本文件中。

您需要等待用户输入数据并单击正确页面上的下一步按钮:

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if(CurPageID = Page.ID) then
  begin
    { Process the page }
    { Read values into variables }
    username := Page.Values[0];
    password := Page.Values[1];
    SaveStringToFile('c:\filename.txt', username+#13#10+password+#13#10, False);
  end;

 Result := True;
end;
Run Code Online (Sandbox Code Playgroud)

还有一些提示:保存名称/密码是不安全的!也使用硬编码路径真的很不寻常......