Java API to perform WMI queries
To install WMI4Java you can add the dependecy to your software project management tool: http://mvnrepository.com/artifact/com.profesorfalken/WMI4Java/1.4.2
For example, for Maven you have just to add to your pom.xml:
<dependency>
<groupId>com.profesorfalken</groupId>
<artifactId>WMI4Java</artifactId>
<version>1.4.2</version>
</dependency>
Instead, you can direct download the JAR file and add it to your classpath. https://repo1.maven.org/maven2/com/profesorfalken/WMI4Java/1.4.2/WMI4Java-1.4.2.jar
List<String> wmiClassesList = WMI4Java.get().listClasses();
List<String> wmiClassesList = WMI4Java.get().namespace("root/WMI").listClasses();
//Example win32_BIOS
Map<String, String> wmiObjectProperties = WMI4Java.get().getWMIObject("Win32_BIOS");
//Example win32_BIOS
Map<String, String> wmiObjectProperties = WMI4Java.get().getRawWMIObjectOutput("Win32_BIOS");
//Example get processes named java.exe
Map<String, String> wmiObjectProperties =
WMI4Java.get().filter(Arrays.asList("$_.Name -eq \"java.exe\"")).getWMIObject("Win32_Process");
//Example get only specific properties from system processes
Map<String, String> wmiObjectProperties =
WMI4Java.get()
.properties(Arrays.asList("Name", "CommandLine", "ProcessId")).getWMIObject("Win32_Process");
WMI4Java uses two different mechanism in order to retrieve WMI information.
-By default, it uses jPowerShell (https://github.com/profesorfalken/jPowerShell) to open a PowerShell session and invoke the command.
-Instead, we can use an implementation based on VBScript that creates and launches an script on background.
Change the used implementation is really simple. For example, to reproduce the last example using VBScript instead of PowerShell:
//Example win32_BIOS
Map<String, String> wmiObjectProperties = WMI4Java.get().VBSEngine().getWMIObject("Win32_BIOS");