Skip to content

Use JNA/WMI instead of PowerShell to list Windows processes - #4718

Draft
janhoy wants to merge 2 commits into
apache:mainfrom
janhoy:jna-wmi-windows-cmdline
Draft

Use JNA/WMI instead of PowerShell to list Windows processes#4718
janhoy wants to merge 2 commits into
apache:mainfrom
janhoy:jna-wmi-windows-cmdline

Conversation

@janhoy

@janhoy janhoy commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

On Windows, SolrProcessManager (used by the bin/solr status CLI) discovers running Solr processes by reading each Java process's command line. Since ProcessHandle does not expose command lines on Windows, it previously spawned powershell.exe running Get-CimInstance -ClassName Win32_Process ... | ConvertTo-Json and parsed the JSON.

This PR replaces that with a direct WMI (Win32_Process) query via JNA (jna-platform), so no external process is spawned and PowerShell no longer needs to be present/enabled.

Changes

  • Add net.java.dev.jna:jna-platform to solr-core.
  • Rewrite commandLinesWindows() to use CoInitializeExWmiQueryCoUninitialize; drop the PowerShell JSON parsing helper and its unit test.
  • Tighten the test security policy: remove the broad <<ALL FILES>> execute grant (only needed to exec powershell) and add the JNA native-library load / jna.* property-read permissions instead.

Notes

  • The WMI code path is Windows-only (Constants.WINDOWS); Linux/macOS behaviour is unchanged and all static checks + SolrProcessManagerTest pass. The live WMI query has not been exercised on real Windows yet.

Draft pending validation on a Windows runner.

SolrProcessManager previously spawned a powershell.exe process running
Get-CimInstance to obtain command lines of Java processes on Windows.
Replace this with a WMI (Win32_Process) query via JNA, avoiding an
external process spawn and the dependency on PowerShell being present.

- Add net.java.dev.jna:jna-platform dependency to solr-core
- Drop the PowerShell JSON parsing helper and its test
- Remove the broad "<<ALL FILES>>" execute grant from the test security
  policy (only needed to exec powershell) and add the JNA native-library
  load / jna.* property-read permissions instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant