Recently, I had to display a list of running Windows services inside a custom Advanced Installer dialog.
My goal was simple:
- Show the service name in the first column (fixed width, 25 characters).
- Append a second column with "Owner:LocalHost" (later updated to show the real Log On As account)
In PowerShell, it’s easy to align columns using PadRight():
Code: Select all
$COL = 25
$items = Get-Service | Where-Object Status -eq 'Running' |
ForEach-Object { $_.Name.PadRight($COL) + 'Owner:localHost' }In the PowerShell console (which uses a monospaced font), this looked perfect.
But once I fed the results into my Advanced Installer ComboBox/ListBox, everything broke — the second column was jagged and misaligned.
The Hidden Problem
The issue wasn’t with PowerShell at all. The problem was fonts:
The PowerShell console uses a monospaced font (every character is the same width).
Advanced Installer dialogs use Segoe UI, a proportional font (characters have different widths).
- "MMMMM" is much wider than "iiiii".
- So "PadRight(25)" ensures character count, but not visual alignment.
The Fix
The cleanest solution turned out to be very simple:
Switch the control’s Text Style to a monospaced font (Consolas or Courier New) in Advanced Installer.
Reference the new text style for my controls:
At runtime, the columns get properly alligned:
Takeaway
If you’re working with ComboBoxes/ListBoxes in Advanced Installer and need aligned columns:
- Don’t rely on PadRight() alone, Windows Installer measures text in dialog units, not raw characters or pixels.
- With proportional fonts (Segoe UI), dialog units don’t map cleanly to character positions, so columns won’t align.
- The simplest fix is to switch the control to a monospaced font (Consolas, Courier New). That way, each dialog unit equals one character width, and your columns line up perfectly.
Sample project is attached, feel free to download and run.
FOLLOW US