Skip to content

fix(windows): replace removed wmic with PowerShell Get-CimInstance#4

Merged
SRWieZ merged 2 commits into
mainfrom
fix/windows-wmic-removed
May 18, 2026
Merged

fix(windows): replace removed wmic with PowerShell Get-CimInstance#4
SRWieZ merged 2 commits into
mainfrom
fix/windows-wmic-removed

Conversation

@SRWieZ
Copy link
Copy Markdown
Member

@SRWieZ SRWieZ commented May 18, 2026

Summary

  • windows-latest GitHub runners now use Windows 11 24H2 / Server 2025 images where wmic has been removed, so Shell::exec('wmic os get …') returned 'wmic' is not recognized… and the Windows constructor crashed with Undefined array key "Caption" before any test could run (see run 26057554808).
  • Switched to Get-CimInstance Win32_OperatingSystem (the supported successor) via PowerShell, formatted to emit the same Caption=… / Version=… / BuildNumber=… lines the existing parser already handles, so the rest of the file is unchanged.
  • Added a ?? '' on the Caption lookup so a future missing key degrades to "not a Server" rather than throwing.

Test plan

  • CI: all windows-latest matrix jobs pass alongside the existing ubuntu/macos ones
  • CI: ubuntu/macos jobs remain green (no shared code touched)

🤖 Generated with Claude Code

SRWieZ and others added 2 commits May 18, 2026 22:12
wmic was removed in Windows 11 24H2 / Server 2025 (the image GitHub's
windows-latest runner now uses), so the constructor crashed with
"Undefined array key 'Caption'" before any test could run. Swap to
Get-CimInstance Win32_OperatingSystem (same data, supported successor)
and emit the same Key=Value lines the existing parser expects. Also
null-coalesce the Caption lookup so a missing key degrades to "not a
Server" instead of throwing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two issues survived the first wmic→PowerShell swap on windows-latest:

1. Win32_OperatingSystem.Version came through empty on the new Server
   image, so getWindowsVersion('') threw InvalidArgumentException from
   the constructor. Read the version from [Environment]::OSVersion
   instead, which is always populated.
2. -Command with single quotes inside a cmd.exe double-quoted argument
   is fragile. Switch to -EncodedCommand (UTF-16LE base64) so the shell
   never has to interpret the script, which removes a whole class of
   future quoting regressions.

Also soften getWindowsVersion to return null on malformed input — the
constructor calls it unconditionally, so a throw there propagates as a
hard crash in any consumer that just wants to print system info.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@SRWieZ SRWieZ merged commit a1b4160 into main May 18, 2026
13 checks passed
@SRWieZ SRWieZ deleted the fix/windows-wmic-removed branch May 18, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant