Skip to content

ramiabughazaleh/WMI4Java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WMI4Java

Java API to perform WMI queries

Installation

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

Basic Usage

List all WMI classes names from root/CIMv2 (default namespace)

    List<String> wmiClassesList = WMI4Java.get().listClasses();

List all WMI classes names from root/WMI

    List<String> wmiClassesList = WMI4Java.get().namespace("root/WMI").listClasses();

Get all the properties of a WMI Object

    //Example win32_BIOS
    Map<String, String> wmiObjectProperties = WMI4Java.get().getWMIObject("Win32_BIOS");

More Advanced Usage

Get raw output in String format

    //Example win32_BIOS
    Map<String, String> wmiObjectProperties = WMI4Java.get().getRawWMIObjectOutput("Win32_BIOS");

Filter results by property value

    //Example get processes named java.exe
    Map<String, String> wmiObjectProperties = 
        WMI4Java.get().filter(Arrays.asList("$_.Name -eq \"java.exe\"")).getWMIObject("Win32_Process");

Get only specific properties

    //Example get only specific properties from system processes
    Map<String, String> wmiObjectProperties = 
        WMI4Java.get()
            .properties(Arrays.asList("Name", "CommandLine", "ProcessId")).getWMIObject("Win32_Process");

How it works

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");

About

Java API to perform WMI queries

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%