Top Description Inners Fields Constructors Methods
com.sun.jna.platform.win32.COM

public Class WbemcliUtil

extends Object
Class Inheritance
Imports
java.util.ArrayList, .EnumMap, .HashMap, .List, .Map, java.util.concurrent.TimeoutException, com.sun.jna.Pointer, .WString, com.sun.jna.platform.win32.Ole32, .OleAuto, .Variant, .Variant.VARIANT, .WinNT.HRESULT, com.sun.jna.platform.win32.COM.Wbemcli.IEnumWbemClassObject, .Wbemcli.IWbemClassObject, .Wbemcli.IWbemLocator, .Wbemcli.IWbemServices, com.sun.jna.ptr.IntByReference

Utility class providing access to Windows Management Interface (WMI) via COM.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
WbemcliUtil.NamespaceProperty

Enum containing the property used for WMI Namespace query.

public static class
WbemcliUtil.WmiQuery<T extends Enum<T>>

Helper class wrapping information required for a WMI query.

public class
WbemcliUtil.WmiResult<T extends Enum<T>>

Helper class wrapping an EnumMap containing the results of a query.

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_NAMESPACE

The default namespace for most WMI queries.

public static final WbemcliUtil
INSTANCE

Instance to generate the WmiQuery class.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static Wbemcli.IWbemServices

Returns:

A service representing the connected namespace, which can be queried. This service may be re-used for multiple queries and should be released by the user
connectServer
(String
The namespace to connect to
namespace
)

Obtains a locator to the WMI server and connects to the specified namespace

public static boolean

Returns:

true if the namespace exists, false otherwise
hasNamespace
(String
The namespace to test
namespace
)

Determine if WMI has the requested namespace.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_NAMESPACEback to summary
public static final String DEFAULT_NAMESPACE

The default namespace for most WMI queries.

INSTANCEback to summary
public static final WbemcliUtil INSTANCE

Instance to generate the WmiQuery class.

Constructor Detail

WbemcliUtilback to summary
public WbemcliUtil()

Method Detail

connectServerback to summary
public static Wbemcli.IWbemServices connectServer(String namespace)

Obtains a locator to the WMI server and connects to the specified namespace

Parameters
namespace:String

The namespace to connect to

Returns:Wbemcli.IWbemServices

A service representing the connected namespace, which can be queried. This service may be re-used for multiple queries and should be released by the user

hasNamespaceback to summary
public static boolean hasNamespace(String namespace)

Determine if WMI has the requested namespace. Some namespaces only exist on newer versions of Windows.

Parameters
namespace:String

The namespace to test

Returns:boolean

true if the namespace exists, false otherwise

com.sun.jna.platform.win32.COM back to summary

private final Enum WbemcliUtil.NamespaceProperty

extends Enum<WbemcliUtil.NamespaceProperty>
Class Inheritance

Enum containing the property used for WMI Namespace query.

Field Summary

Modifier and TypeField and Description
public static final WbemcliUtil.NamespaceProperty

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static WbemcliUtil.NamespaceProperty
public static WbemcliUtil.NamespaceProperty[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

NAMEback to summary
public static final WbemcliUtil.NamespaceProperty NAME

Constructor Detail

NamespacePropertyback to summary
private NamespaceProperty()

Method Detail

valueOfback to summary
public static WbemcliUtil.NamespaceProperty valueOf(String name)
valuesback to summary
public static WbemcliUtil.NamespaceProperty[] values()
com.sun.jna.platform.win32.COM back to summary

public Class WbemcliUtil.WmiQuery<T extends java.lang.Enum<T>>

extends Object
Class Inheritance

Helper class wrapping information required for a WMI query.

Field Summary

Modifier and TypeField and Description
private String
private Class<T>
private String

Constructor Summary

AccessConstructor and Description
public
WmiQuery(String
The WMI namespace to use.
nameSpace
,
String
The WMI class to use. Optionally include a WQL WHERE clause with filters results to properties matching the input.
wmiClassName
,
Class<T>
An enum for type mapping.
propertyEnum
)

Instantiate a WmiQuery.

public
WmiQuery(String
The WMI Class to use. May include a WHERE clause with filtering conditions.
wmiClassName
,
Class<T>
An Enum that contains the properties to query
propertyEnum
)

Instantiate a WMI Query in the default namespace

Method Summary

Modifier and TypeMethod and Description
private static <T extends Enum<T>> WbemcliUtil.WmiResult<T>

Returns:

A WmiResult object encapsulating an EnumMap which will hold the results. Values, that are not supported by this helper (Dispatch, Unknown, SAFEARRAY) are not returned and reported as null.
enumerateProperties
(Wbemcli.IEnumWbemClassObject
The enumerator with the results
enumerator
,
Class<T>
The enum containing the properties to enumerate, which are the keys to the WmiResult map
propertyEnum
,
int
Number of milliseconds to wait for results before timing out. If IEnumWbemClassObject#WBEM_INFINITE (-1), will always wait for results.
timeout
)

Enumerate the results of a WMI query.

public WbemcliUtil.WmiResult<T>

Returns:

a WmiResult object containing the query results, wrapping an EnumMap
execute
()

Query WMI for values, with no timeout.

public WbemcliUtil.WmiResult<T>

Returns:

a WmiResult object containing the query results, wrapping an EnumMap
execute
(int
Number of milliseconds to wait for results before timing out. If IEnumWbemClassObject#WBEM_INFINITE (-1), will always wait for results. If a timeout occurs, throws a TimeoutException.
timeout
)

Query WMI for values, with a specified timeout.

public String

Returns:

The namespace
getNameSpace
()

public Class<T>

Returns:

The enum containing the properties
getPropertyEnum
()

public String

Returns:

The class name
getWmiClassName
()

private static <T extends Enum<T>> Wbemcli.IEnumWbemClassObject

Returns:

An enumerator to receive the results of the query
selectProperties
(Wbemcli.IWbemServices
A WbemServices object to make the calls
svc
,
WbemcliUtil.WmiQuery<T>
A WmiQuery object encapsulating the details of the query
query
)

Selects properties from WMI.

public void
setNameSpace(String
The namespace to set
nameSpace
)

public void
setWmiClassName(String
The classname to set
wmiClassName
)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nameSpaceback to summary
private String nameSpace
propertyEnumback to summary
private Class<T> propertyEnum
wmiClassNameback to summary
private String wmiClassName

Constructor Detail

WmiQueryback to summary
public WmiQuery(String nameSpace, String wmiClassName, Class<T> propertyEnum)

Instantiate a WmiQuery.

Parameters
nameSpace:String

The WMI namespace to use.

wmiClassName:String

The WMI class to use. Optionally include a WQL WHERE clause with filters results to properties matching the input.

propertyEnum:Class<T>

An enum for type mapping.

WmiQueryback to summary
public WmiQuery(String wmiClassName, Class<T> propertyEnum)

Instantiate a WMI Query in the default namespace

Parameters
wmiClassName:String

The WMI Class to use. May include a WHERE clause with filtering conditions.

propertyEnum:Class<T>

An Enum that contains the properties to query

Method Detail

enumeratePropertiesback to summary
private static <T extends Enum<T>> WbemcliUtil.WmiResult<T> enumerateProperties(Wbemcli.IEnumWbemClassObject enumerator, Class<T> propertyEnum, int timeout) throws TimeoutException

Enumerate the results of a WMI query. This method is called while results are still being retrieved and may iterate in the forward direction only.

Parameters
enumerator:Wbemcli.IEnumWbemClassObject

The enumerator with the results

propertyEnum:Class<T>

The enum containing the properties to enumerate, which are the keys to the WmiResult map

timeout:int

Number of milliseconds to wait for results before timing out. If IEnumWbemClassObject#WBEM_INFINITE (-1), will always wait for results.

Returns:WbemcliUtil.WmiResult<T>

A WmiResult object encapsulating an EnumMap which will hold the results. Values, that are not supported by this helper (Dispatch, Unknown, SAFEARRAY) are not returned and reported as null.

Exceptions
TimeoutException:
if the query times out before completion
executeback to summary
public WbemcliUtil.WmiResult<T> execute()

Query WMI for values, with no timeout.

Returns:WbemcliUtil.WmiResult<T>

a WmiResult object containing the query results, wrapping an EnumMap

executeback to summary
public WbemcliUtil.WmiResult<T> execute(int timeout) throws TimeoutException

Query WMI for values, with a specified timeout.

Parameters
timeout:int

Number of milliseconds to wait for results before timing out. If IEnumWbemClassObject#WBEM_INFINITE (-1), will always wait for results. If a timeout occurs, throws a TimeoutException.

Returns:WbemcliUtil.WmiResult<T>

a WmiResult object containing the query results, wrapping an EnumMap

Exceptions
TimeoutException:
if the query times out before completion
getNameSpaceback to summary
public String getNameSpace()
Returns:String

The namespace

getPropertyEnumback to summary
public Class<T> getPropertyEnum()
Returns:Class<T>

The enum containing the properties

getWmiClassNameback to summary
public String getWmiClassName()
Returns:String

The class name

selectPropertiesback to summary
private static <T extends Enum<T>> Wbemcli.IEnumWbemClassObject selectProperties(Wbemcli.IWbemServices svc, WbemcliUtil.WmiQuery<T> query)

Selects properties from WMI. Returns immediately (asynchronously), even while results are being retrieved; results may begun to be enumerated in the forward direction only.

Parameters
svc:Wbemcli.IWbemServices

A WbemServices object to make the calls

query:WbemcliUtil.WmiQuery<T>

A WmiQuery object encapsulating the details of the query

Returns:Wbemcli.IEnumWbemClassObject

An enumerator to receive the results of the query

setNameSpaceback to summary
public void setNameSpace(String nameSpace)
Parameters
nameSpace:String

The namespace to set

setWmiClassNameback to summary
public void setWmiClassName(String wmiClassName)
Parameters
wmiClassName:String

The classname to set

com.sun.jna.platform.win32.COM back to summary

public Class WbemcliUtil.WmiResult<T extends java.lang.Enum<T>>

extends Object
Class Inheritance

Helper class wrapping an EnumMap containing the results of a query.

Field Summary

Modifier and TypeField and Description
private Map<T, Integer>
private Map<T, List<Object>>
private int
private Map<T, Integer>

Constructor Summary

AccessConstructor and Description
public
WmiResult(Class<T>
The enum associated with this map
propertyEnum
)

Method Summary

Modifier and TypeMethod and Description
private void
add(int
The Variant type of this object
vtType
,
int
The CIM type of this property
cimType
,
T
The property (column) to store
property
,
Object
The object to store
o
)

Adds a value to the WmiResult at the next index for that property

public int

Returns:

An integer representing the CIM type
getCIMType
(T
The property (column) whose type to fetch
property
)

Gets the CIM type from the WmiResult.

public int

Returns:

The number of results in each mapped list
getResultCount
()

public Object

Returns:

The Object containing the specified value, which may be null
getValue
(T
The property (column) to fetch
property
,
int
The index (row) to fetch
index
)

Gets a value from the WmiResult, which may be null.

public int

Returns:

An integer representing the Variant type
getVtType
(T
The property (column) whose type to fetch
property
)

Gets the Variant type from the WmiResult.

private void
incrementResultCount()

Increment the result count by one.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cimTypeMapback to summary
private Map<T, Integer> cimTypeMap
propertyMapback to summary
private Map<T, List<Object>> propertyMap
resultCountback to summary
private int resultCount
vtTypeMapback to summary
private Map<T, Integer> vtTypeMap

Constructor Detail

WmiResultback to summary
public WmiResult(Class<T> propertyEnum)
Parameters
propertyEnum:Class<T>

The enum associated with this map

Method Detail

addback to summary
private void add(int vtType, int cimType, T property, Object o)

Adds a value to the WmiResult at the next index for that property

Parameters
vtType:int

The Variant type of this object

cimType:int

The CIM type of this property

property:T

The property (column) to store

o:Object

The object to store

getCIMTypeback to summary
public int getCIMType(T property)

Gets the CIM type from the WmiResult. The integer value is defined as a CIM_* constant in the Wbemcli interface.

Parameters
property:T

The property (column) whose type to fetch

Returns:int

An integer representing the CIM type

getResultCountback to summary
public int getResultCount()
Returns:int

The number of results in each mapped list

getValueback to summary
public Object getValue(T property, int index)

Gets a value from the WmiResult, which may be null. User must check for null and cast the result. Types correlate to the CIM Type of the enumerated WMI property and will be consistent for a given property, and may be validated by the user using getVtType or the Class of the returned Object.

Parameters
property:T

The property (column) to fetch

index:int

The index (row) to fetch

Returns:Object

The Object containing the specified value, which may be null

getVtTypeback to summary
public int getVtType(T property)

Gets the Variant type from the WmiResult. The integer value is defined as a VT_* constant in the com.sun.jna.platform.win32.Variant interface.

Parameters
property:T

The property (column) whose type to fetch

Returns:int

An integer representing the Variant type

incrementResultCountback to summary
private void incrementResultCount()

Increment the result count by one.