Installing JWbem is a simple two step process:

1. Add the Hyper9 Maven Repository to your Maven settings file or to your project's POM file.

    <name>Hyper9 Maven Repository</name>

2. List JWbem as a dependency in your project's POM file.


And that's all there is to installing JWbem.


Using JWbem is a fairly straight-forward process.

  1. Establish a connection to a Microsoft Windows system
  2. Execute Windows Query Language (WQL) against the remote system


Here are two quick examples for connecting to a remote Microsoft Windows Hyper-V server and listing its virtual machines.

Establish a connection to a Microsoft Windows system

This example shows how to connect to a remote Hyper-V server's virtualization namespace.

import com.hyper9.jwbem.SWbemLocator;
import com.hyper9.jwbem.SWbemServices;


// The IP address or FQDN of the Windows server to connect to.
String serverName = "hyperv.hyper9.local";
// The CIM namespace to connect to.
String cimNamespace = "root\\virtualization";
// The name of the user to connect as. The format of the user name supports
String userName = "Hyper9\\akutz";
// The passprase for the given user.
String passphrase = "passphrase";
// Create a locator object.
SWbemLocator loc = new SWbemLocator();

// Connect to the Windows server and return a services object.
SWbemServices svc = loc.connect(serverName, "", cimNamespace, username, passphrase);

Execute Windows Query Language (WQL) against the remote system

This example shows how to enumerate all of the virtual machines on the Hyper-V server we established a connection to in the previous example.

import com.hyper9.jwbem.SWbemObjectSet;
import com.hyper9.jwbem.msvm.MsvmComputerSystem;


// Define the WQL query that returns all of a Hyper-V's virtual machines.
String wql = "SELECT * FROM Msvm_ComputerSystem WHERE Caption='Virtual Machine'";

// Execute the query.
SWbemObjectSet<MsvmComputerSystem> compSysSet = svc.execQuery(wql, MsvmComputerSystem.class);

// Print the names of the virtual machines.
for (MsvmComputerSystem cs : compSysSet)

CIM Namespaces

It is important to remember that when you establish a connection to a remote Windows system with JWbem, all of that system's data is not available to you at once. This is because you must specify a CIM namespace when connecting to the Windows system. Common namespaces include:

  • root\virtualization
  • root\cimv2

To get a Windows system's system properties you should connect to the cimv2 namespace just as if you wish to know about all things Hyper-V you will want to connect to the virtualization namespace.