Class WMI4Java
public class WMI4Java extends Object
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 Summary
Modifier and Type Method Description WMI4JavacomputerName(String computerName)Set an specific computer name
By default it uses .WMI4Javafilters(List<String> filters)Sets the list of used filters when performing WMI query.static WMI4Javaget()Static creation of instanceStringgetRawWMIObjectOutput(WMIClass wmiClass)Query all the raw object data for an specific classStringgetRawWMIObjectOutput(String wmiClass)Query all the raw object data for an specific classMap<String,String>getWMIObject(WMIClass wmiClass)Query all the object data for an specific class
WARNINGN Notice that this method return a flat object.Map<String,String>getWMIObject(String wmiClass)Query all the object data for an specific class
WARNINGN Notice that this method return a flat object.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.List<Map<String,String>>getWMIObjectList(String 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.List<String>listClasses()Query and list the WMI classesList<String>listProperties(String wmiClass)Query a WMI class and return all the available propertiesWMI4Javanamespace(String namespace)Set an specific namespace
By default it uses root/cimv2 namespaceWMI4JavaPowerShellEngine()Forces the use of PowerShell engine in order to query WMIWMI4Javaproperties(List<String> properties)Sets the list of required object properties.WMI4JavaVBSEngine()Forces the use of VBS engine in order to query WMI
-
Method Details
-
get
Static creation of instance- Returns:
- WMI4Java
-
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
Set an specific computer name
By default it uses .- Parameters:
computerName-- Returns:
- object instance used to chain calls
-
PowerShellEngine
Forces the use of PowerShell engine in order to query WMI- Returns:
- object instance used to chain calls
-
VBSEngine
Forces the use of VBS engine in order to query WMI- Returns:
- object instance used to chain calls
-
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
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
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
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
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
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
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
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
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
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
-