Class Win32UserAccountService

java.lang.Object
io.github.eggy03.ferrumx.windows.service.user.Win32UserAccountService
All Implemented Interfaces:
CommonServiceInterface<Win32UserAccount>

public class Win32UserAccountService extends Object implements CommonServiceInterface<Win32UserAccount>
Service class for fetching information about User Accounts in a Windows System.

This class executes the Cimv2.WIN32_USER_ACCOUNT PowerShell command and maps the resulting JSON into an immutable list of Win32UserAccount objects.

Usage examples

// Convenience API (creates its own short-lived session)
Win32UserAccountService service = new Win32UserAccountService();
List<Win32UserAccount> ua = service.get();

// API with re-usable session (caller manages session lifecycle)
try (PowerShell session = PowerShell.openSession()) {
    Win32UserAccountService service = new Win32UserAccountService();
    List<Win32UserAccount> ua = service.get(session);
}

// Executor-safe API (isolated PowerShell process per call)
Win32UserAccountService service = new Win32UserAccountService();
List<Win32UserAccount> ua = service.get(10);

Execution models and concurrency

This service supports multiple PowerShell execution strategies:

  • jPowerShell-based execution via get() and get(PowerShell):
    These methods rely on jPowerShell sessions. Due to internal global configuration of jPowerShell, the PowerShell sessions launched by it is not safe to use concurrently across multiple threads or executors. Running these methods in parallel may result in runtime exceptions.
  • Isolated PowerShell execution via get(long timeout):
    This method doesn't rely on jPowerShell and instead, launches a standalone PowerShell process per invocation using TerminalUtility. Each call is fully isolated and safe to use in multithreaded and executor-based environments.

For concurrent or executor-based workloads, prefer get(long timeout).

Since:
3.0.0
  • Constructor Details

    • Win32UserAccountService

      public Win32UserAccountService()
  • Method Details

    • get

      @UsesJPowerShell @NotNull public @NotNull @Unmodifiable List<Win32UserAccount> get()
      Retrieves an immutable list of user accounts present in the system.

      Each invocation creates and uses a short-lived PowerShell session internally.

      Specified by:
      get in interface CommonServiceInterface<Win32UserAccount>
      Returns:
      an immutable list of Win32UserAccount objects representing the user accounts. Returns an empty list if no user accounts are detected.
      Since:
      3.0.0
    • get

      @UsesJPowerShell @NotNull public @NotNull @Unmodifiable List<Win32UserAccount> get(@NonNull @NonNull com.profesorfalken.jpowershell.PowerShell powerShell)
      Retrieves an immutable list of user accounts using the caller's PowerShell session.
      Specified by:
      get in interface CommonServiceInterface<Win32UserAccount>
      Parameters:
      powerShell - an existing PowerShell session managed by the caller
      Returns:
      an immutable list of Win32UserAccount objects representing the user accounts. Returns an empty list if no user accounts are detected.
      Since:
      3.0.0
    • get

      @IsolatedPowerShell @NotNull public @NotNull @Unmodifiable List<Win32UserAccount> get(long timeout)
      Retrieves an immutable list of user accounts using an isolated PowerShell process with a configurable timeout.

      Each invocation creates an isolated PowerShell process, which is pre-maturely terminated if execution exceeds the specified timeout.

      Specified by:
      get in interface CommonServiceInterface<Win32UserAccount>
      Parameters:
      timeout - the maximum time (in seconds) to wait for the PowerShell command to complete before terminating the process
      Returns:
      an immutable list of Win32UserAccount objects representing the user accounts. Returns an empty list if no user accounts are detected.
      Since:
      3.1.0