Class WMI4Java

java.lang.Object
com.profesorfalken.wmi4java.WMI4Java

public class WMI4Java
extends Object
Class that allows to get WMI information.
It should be instantiated using an static method and can be easily configured using chained methods.

Ex: WMI4Java.get().computerName(".").namespace("root/cimv2").getWMIObject("Win32_BaseBoard");

The default computername will be . and the default namespace root/cimv2

All method will return an unchecked exception of type WMIException that can be optionally handled (thanks to guilhermeoc97 for proposing an exception mechanism).

It supports two implementations:
-One based on PowerShell console (see project jPowerShell)
-The other based on a VB script (many thanks to Scriptomatic tool!)

But default it will use PowerShell but we can force an specific engine easily.

Author:
Javier Garcia Alonso
See Also:
jPowerShell, Scriptomatic v2
  • Method Details

    • get

      public static WMI4Java get()
      Static creation of instance
      Returns:
      WMI4Java
    • namespace

      public WMI4Java namespace​(String namespace)
      Set an specific namespace
      By default it uses root/cimv2 namespace
      Parameters:
      namespace - used namespace. Ex "root/WMI"
      Returns:
      object instance used to chain calls
    • computerName

      public WMI4Java computerName​(String computerName)
      Set an specific computer name
      By default it uses .
      Parameters:
      computerName -
      Returns:
      object instance used to chain calls
    • PowerShellEngine

      public WMI4Java PowerShellEngine()
      Forces the use of PowerShell engine in order to query WMI
      Returns:
      object instance used to chain calls
    • VBSEngine

      public WMI4Java VBSEngine()
      Forces the use of VBS engine in order to query WMI
      Returns:
      object instance used to chain calls
    • properties

      public WMI4Java properties​(List<String> properties)
      Sets the list of required object properties.
      Parameters:
      properties - list with the name of the properties we want to extract
      Returns:
      object instance used to chain calls
    • filters

      public WMI4Java filters​(List<String> filters)
      Sets the list of used filters when performing WMI query.
      Parameters:
      filters - list with the different filters to apply
      Returns:
      object instance used to chain calls
    • listClasses

      public List<String> listClasses() throws WMIException
      Query and list the WMI classes
      Returns:
      a list with the name of existing classes in the system
      Throws:
      WMIException
      See Also:
      WMI Classes - MSDN
    • listProperties

      public List<String> listProperties​(String wmiClass) throws WMIException
      Query a WMI class and return all the available properties
      Parameters:
      wmiClass - the WMI class to query
      Returns:
      a list with the name of existing properties in the class
      Throws:
      WMIException
    • getWMIObject

      public Map<String,​String> getWMIObject​(WMIClass wmiClass)
      Query all the object data for an specific class
      WARNINGN Notice that this method return a flat object. That means that if you need to retrieve a list of objects it will not work as expected. Every time it find an existing object key it overrides it.

      In order to retrieve a list of objects, use instead getWMIObjectList(WMIClass)

      Parameters:
      wmiClass - Enum that contains the most used classes (root/cimv2)
      Returns:
      map with the key and the value of all the properties of the object
    • getWMIObject

      public Map<String,​String> getWMIObject​(String wmiClass) throws WMIException
      Query all the object data for an specific class
      WARNINGN Notice that this method return a flat object. That means that if you need to retrieve a list of objects it will not work as expected. Every time it find an existing object key it overrides it.

      In order to retrieve a list of objects, use instead getWMIObjectList(String)

      Parameters:
      wmiClass - Enum that contains the most used classes (root/cimv2)
      Returns:
      map with the key and the value of all the properties of the object
      Throws:
      WMIException
    • getWMIObjectList

      public List<Map<String,​String>> getWMIObjectList​(WMIClass wmiClass)
      Query a list of object data for an specific class
      This method should be used to retrieve a list of objects instead of a flat key/value object.
      For example, you can use it to retrieve hardware elements information (processors, printers, screens, etc)
      Parameters:
      wmiClass - Enum that contains the most used classes (root/cimv2)
      Returns:
      List of key/value elements. Each element in the list is a found object
    • getWMIObjectList

      public List<Map<String,​String>> getWMIObjectList​(String wmiClass) throws WMIException
      Query a list of object data for an specific class
      This method should be used to retrieve a list of objects instead of a flat key/value object.
      For example, you can use it to retrieve hardware elements information (processors, printers, screens, etc)
      Parameters:
      wmiClass - Enum that contains the most used classes (root/cimv2)
      Returns:
      List of key/value elements. Each element in the list is a found object
      Throws:
      WMIException
    • getRawWMIObjectOutput

      public String getRawWMIObjectOutput​(WMIClass wmiClass)
      Query all the raw object data for an specific class
      Parameters:
      wmiClass - Enum that contains the most used classes (root/cimv2)
      Returns:
      string with all the properties of the object
    • getRawWMIObjectOutput

      public String getRawWMIObjectOutput​(String wmiClass) throws WMIException
      Query all the raw object data for an specific class
      Parameters:
      wmiClass - string with the name of the class to query
      Returns:
      string with all the properties of the object
      Throws:
      WMIException