【问题标题】:Query list of Windows accounts in Inno Setup在 Inno Setup 中查询 Windows 账户列表
【发布时间】:2020-12-11 10:55:52
【问题描述】:

在我的 Inno Setup 项目中,我需要允许用户从自定义页面上的所有本地帐户列表中选择一个帐户。所选帐户将用于安装具有自定义凭据的服务。 我该怎么做?

提前谢谢你!

【问题讨论】:

    标签: inno-setup pascalscript


    【解决方案1】:

    您可以使用WMI Win32_UserAccount class查询帐号列表。

    [Run]
    Filename: sc.exe; Parameters: ... {code:GetAccount}
    
    [Code]
    
    var
      AccountPage: TInputOptionWizardPage;
    
    procedure InitializeWizard();
    var
      WMIService: Variant;
      WbemLocator: Variant;
      WbemObjectSet: Variant;
      I: Integer;
    begin
      Log('InitializeWizard');
      AccountPage := CreateInputOptionPage(
        wpSelectTasks, 'Service account', '', 'Please select account for the service:',
        True, True);
    
      WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
      WMIService := WbemLocator.ConnectServer('localhost', 'root\CIMV2');
      WbemObjectSet :=
        WMIService.ExecQuery('SELECT * FROM Win32_UserAccount');
      if not VarIsNull(WbemObjectSet) then
      begin
        for I := 0 to WbemObjectSet.Count - 1 do
        begin
          AccountPage.Add(WbemObjectSet.ItemIndex(I).Caption);
        end;
        AccountPage.SelectedValueIndex := 0;
      end;
    end;
    
    function GetAccount(Param: string): string;
    var
      I: Integer;
    begin
      for I := 0 to AccountPage.CheckListBox.Items.Count - 1 do
      begin
        if AccountPage.Values[I] then Result := AccountPage.CheckListBox.Items[I];
      end;
    end;
    


    相关问题:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      • 1970-01-01
      • 2016-07-18
      • 1970-01-01
      • 2017-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多