Consultar lista de cuentas de Windows en Inno Setup
Dec 11 2020
En mi proyecto Inno Setup necesito permitir que el usuario elija una cuenta de la lista de todas las cuentas locales en una página personalizada. La cuenta seleccionada se utilizará para instalar un servicio con credencial personalizada. ¿Cómo puedo hacer esto?
¡Gracias de antemano!
Respuestas
1 MartinPrikryl Dec 11 2020 at 20:03
Puede utilizar la clase WMIWin32_UserAccount para consultar la lista de cuentas.
[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;

Preguntas relacionadas:
- Inno Setup Cree accesos directos individuales en todos los escritorios de todos los usuarios
- Inno Setup para crear un usuario en Windows