WinRM Java Client 2.0.00
- Getting Started Overview Installation Preparing the Windows Host
- Usage WQL Queries Remote Commands File Transfers Command-Line Client Authentication TLS / HTTPS Timeouts and Errors
- Reference Migrating from 1.x Legacy API Javadoc (API)
- Project Documentation Project Information 9 Project Reports 8
WinRM Java Client
Overview
The WinRM Java Client is a small library that talks to the Windows Remote Management (WS-Management) service on a remote Windows host. It lets a Java application:
- run WQL / WMI queries such as
SELECT Name, State FROM Win32_Serviceand read the rows back (WQL Queries[1]), and - execute remote commands, capturing standard output, standard error and the exit code — optionally copying local script files to the host first (Remote Commands[2]).
Both operations can also stream: WQL rows are consumed page by page as they arrive (stream()), and command output is consumed while the command is still running (start(), returning a java.lang.Process-like handle) — memory stays bounded regardless of the result size.
It supports NTLM over HTTP (with message encryption) and HTTPS, and Kerberos (SPNEGO) over HTTPS (Authentication[3]).
Since 2.0.0 the client has zero runtime dependencies (no Apache CXF / JAX-WS / JAXB stack, no SMB stack) and is immune by construction to JAXP ServiceLoader conflicts, because it uses the JDK-default XML factories. Problems are reported through exceptions only — the library pulls in no logging framework.
Upgrading from 1.x? Version 2.0.0 removed the legacy Apache CXF backend and now validates TLS certificates and verifies hostnames by default. If you connect over HTTPS to hosts with self-signed certificates, read Migrating from 1.x[4] first.
Add the dependency
The library is published on Maven Central[5].
Maven
<dependency>
<groupId>org.metricshub</groupId>
<artifactId>winrm-java</artifactId>
<version>2.0.00</version>
</dependency>
Gradle (Groovy)
implementation 'org.metricshub:winrm-java:2.0.00'
Gradle (Kotlin)
implementation("org.metricshub:winrm-java:2.0.00")
See Installation[6] for the coordinates, the supported JDKs, and the standalone command-line jar.
A first WQL query
On the target host, WinRM must be enabled and the account must have sufficient privileges. Windows Server 2012 and later have WinRM enabled by default and an administrator account works with no configuration; Windows 10 / 11, non-administrator accounts, and local (non-domain) administrator accounts all need host-side setup. See Preparing the Windows Host[7].
Everything starts with the fluent WinRMClient[8] builder — one client authenticates once and can run any number of queries and commands over the same connection:
import java.time.Duration;
import org.metricshub.winrm.WinRMClient;
import org.metricshub.winrm.WqlResult;
import org.metricshub.winrm.WqlRow;
public class Example {
public static void main(String[] args) {
try (WinRMClient client = WinRMClient.builder("server.example.com")
.credentials("DOMAIN\\Administrator", "the-password".toCharArray())
.timeout(Duration.ofSeconds(30))
.build()) {
WqlResult result = client.wql("SELECT Name, State FROM Win32_Service").execute();
System.out.println(result.columns()); // [Name, State]
for (WqlRow row : result) {
System.out.println(row.string("Name") + " is " + row.string("State"));
}
}
}
}
Remote commands work the same way:
CommandResult result = client.command("ipconfig /all").execute();
System.out.println(result.stdout());
Failures are reported through the unchecked WinRMClientException[9] hierarchy. The static one-shot helpers that predate WinRMClient (WinRMWqlExecutor.executeWql(...)[10], WinRMCommandExecutor.execute(...)[11]) remain available and unchanged, with their checked exceptions.
Where to go next
- Installation[6] — coordinates, supported JDKs, and the standalone CLI jar
- Preparing the Windows Host[7] — prerequisites on the target: enabling WinRM and the privileges the account needs
- WQL Queries[1] — query WMI and read the result
- Remote Commands[2] — run commands and copy files to the host
- File Transfers[12] — how files are copied through the WinRM channel
- Command-Line Client[13] — the standalone jar's manual page
- Authentication[3] — NTLM and Kerberos
- TLS / HTTPS[14] — certificate validation and trust stores
- Timeouts and Errors[15] — timeout semantics and the exception surface
- Migrating from 1.x[4] — the 2.0.0 breaking changes, and moving to the fluent API
- Legacy API[16] — the static one-shot helpers that predate
WinRMClient
- [1] wql.html
- [2] commands.html
- [3] authentication.html
- [4] migrating-from-1x.html
- [5] https://central.sonatype.com/artifact/org.metricshub/winrm-java
- [6] installation.html
- [7] preparing-the-host.html
- [8] apidocs/org/metricshub/winrm/WinRMClient.html
- [9] apidocs/org/metricshub/winrm/exceptions/WinRMClientException.html
- [10] apidocs/org/metricshub/winrm/wql/WinRMWqlExecutor.html
- [11] apidocs/org/metricshub/winrm/command/WinRMCommandExecutor.html
- [12] file-transfers.html
- [13] cli.html
- [14] tls.html
- [15] timeouts-and-errors.html
- [16] legacy.html
