Skip to content

fix(windows): fall back to Get-CimInstance when wmic is missing (Win11 24H2+)#7

Open
yunjeongiya wants to merge 1 commit into
TheStack-ai:mainfrom
yunjeongiya:fix/windows-wmic-cim-fallback
Open

fix(windows): fall back to Get-CimInstance when wmic is missing (Win11 24H2+)#7
yunjeongiya wants to merge 1 commit into
TheStack-ai:mainfrom
yunjeongiya:fix/windows-wmic-cim-fallback

Conversation

@yunjeongiya

Copy link
Copy Markdown

Fixes #6.

Problem

wmic is gone by default on Windows 11 24H2+ / Server 2025. ProcessTree.fromWMIC() then returns an empty tree, so zclean reports "0 zombies" and never cleans anything on those machines. CI runs only ubuntu-latest / macos-latest, so this path was never exercised.

Change

  • ProcessTree.fromCIM() — enumerate via Get-CimInstance Win32_Process (PowerShell), producing the exact same {pid, ppid, cmd, mem, age, startTime} shape as fromWMIC() / fromPS().
    • Invoked with execFileSync (no shell) + -EncodedCommand (no quoting issues).
    • $ProgressPreference='SilentlyContinue' keeps stderr clean.
  • ProcessTree.fromWindows() — try fromWMIC() first (keeps the existing fast path where wmic is still present), fall back to fromCIM() when wmic is missing or yields nothing.
  • build() now calls fromWindows() on win32. The non-Windows (fromPS) path is unchanged.
  • Silence the 'wmic' is not recognized stderr leak in fromWMIC() so the fallback probe is quiet.
  • Tests: platform-aware fromWindows / fromCIM cases (cross-platform "doesn't throw" + win32-only live-enumeration assertions).

Verification (Windows 11, build 26200, no wmic)

fromWMIC size = 0      # no wmic
fromCIM  size = 587    # PowerShell CIM works
build()  size = 587    # falls back to CIM

node --test is green except the pre-existing unix-only fromPS live test (which passes on the ubuntu/macos CI).

Notes

  • Kept wmic as the primary Windows path to preserve current behaviour/perf; happy to make CIM the default and drop wmic entirely if you'd prefer (wmic is end-of-life).
  • Consider adding windows-latest to the CI matrix — it would have caught this. The fromPS live test would need a unix guard first.

wmic is deprecated and absent by default on Windows 11 24H2+ / Server 2025.
ProcessTree.fromWMIC() then returns an empty tree, so zclean reports
"0 zombies" and never cleans anything on those machines. CI only runs
ubuntu/macos, so this Windows path was never exercised.

- Add ProcessTree.fromCIM(): enumerate via Get-CimInstance Win32_Process
  (PowerShell), producing the same {pid,ppid,cmd,mem,age,startTime} shape as
  fromWMIC/fromPS. Invoked with execFileSync + -EncodedCommand (no shell, no
  quoting issues); $ProgressPreference=SilentlyContinue keeps stderr clean.
- Add ProcessTree.fromWindows(): try wmic first (keeps the fast path where it
  still exists), fall back to fromCIM() when wmic is missing or yields nothing.
- build() uses fromWindows() on win32; non-Windows path unchanged.
- Silence the "'wmic' is not recognized" stderr leak in fromWMIC().
- Tests: platform-aware fromWindows/fromCIM cases.
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.

Windows: process enumeration broken on Win11 24H2+ (wmic removed) — silently reports 0 zombies

1 participant