Inno Setup to create a user in Windows

邮差的信 提交于 2021-02-07 10:44:09

问题


I´m start user in inno Setup, but I need to create an user in Windows with a password that need input during installation.

Like in CheckSerial where is needed input a name, I need someway to cap this name and other field to insert a password.

On DOS I can create a user with:

net user USER PWD /add /fullname:"USER" /comment:"TEST" /expires:never /passwordchg:no

I got it in

[Run]
Filename: net.exe; parameters: "user USER PWD /add /fullname:""USER"" /comment:""TEST"" /expires:never /passwordchg:no"

But I need input name and password of this user. I think it's possible in [Code].


回答1:


There is a great example on how to get user data from a custom page and use it with "{code:FunctionName|Argument}" in other sections: https://github.com/jrsoftware/issrc/blob/master/Examples/CodeDlg.iss

Short overview:

  • Add a TInputQueryWizardPage in InitializeWizard.

    [Code]
    var
      UserPage: TInputQueryWizardPage;
    
    procedure InitializeWizard;
    begin
      UserPage := CreateInputQueryPage(wpWelcome,
        'Personal Information', 'Who are you?',
        'Please specify your name and password.');
      UserPage.Add('Name:', False);
      UserPage.Add('Password:', True);
    end;
    
    
  • Add a function called GetUser like that returns the requested value:

    function GetUser(Param: String): String;
    begin
      if Param = 'Name' then
        Result := UserPage.Values[0]
      else if Param = 'Password' then
        Result := UserPage.Values[1];
    end;
    
  • Use the input data in the Run command:

    [Run]
    Filename: net.exe; parameters: "user {code:GetUser|Name} {code:GetUser|Password} /add /fullname:""USER"" /comment:""TEST"" /expires:never /passwordchg:no"
    


来源:https://stackoverflow.com/questions/33045837/inno-setup-to-create-a-user-in-windows

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