Package oshi.util.platform.windows
Class WmiUtil
- java.lang.Object
-
- oshi.util.platform.windows.WmiUtil
-
@ThreadSafe public final class WmiUtil extends java.lang.Object
Helper class for WMI
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
CLASS_CAST_MSG
static java.lang.String
OHM_NAMESPACE
The namespace where Open Hardware Monitor publishes to WMI,OHM_NAMESPACE="ROOT\\OpenHardwareMonitor"
.
-
Constructor Summary
Constructors Modifier Constructor Description private
WmiUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.lang.Enum<T>>
java.lang.StringgetDateString(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Date value from a WmiResult as a String in ISO 8601 formatstatic <T extends java.lang.Enum<T>>
java.time.OffsetDateTimegetDateTime(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a DateTime value from a WmiResult as an OffsetDateTimestatic <T extends java.lang.Enum<T>>
floatgetFloat(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Float value from a WmiResultprivate static <T extends java.lang.Enum<T>>
intgetInt(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
static <T extends java.lang.Enum<T>>
java.lang.StringgetRefString(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Reference value from a WmiResult as a Stringstatic <T extends java.lang.Enum<T>>
intgetSint32(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Sint32 value from a WmiResult.private static <T extends java.lang.Enum<T>>
java.lang.StringgetStr(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
static <T extends java.lang.Enum<T>>
java.lang.StringgetString(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a String value from a WmiResultstatic <T extends java.lang.Enum<T>>
intgetUint16(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Uint16 value from a WmiResult.static <T extends java.lang.Enum<T>>
intgetUint32(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets an UINT32 value from a WmiResult.static <T extends java.lang.Enum<T>>
longgetUint32asLong(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets an UINT32 value from a WmiResult as a long, preserving the unsignedness.static <T extends java.lang.Enum<T>>
longgetUint64(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Uint64 value from a WmiResult (parsing the String).static <T extends java.lang.Enum<T>>
java.lang.StringqueryToString(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiQuery<T> query)
Translate a WmiQuery to the actual query string
-
-
-
Field Detail
-
OHM_NAMESPACE
public static final java.lang.String OHM_NAMESPACE
The namespace where Open Hardware Monitor publishes to WMI,OHM_NAMESPACE="ROOT\\OpenHardwareMonitor"
. This namespace is not built-in to WMI, so if OHM is not running would result in unnecessary log messages.- See Also:
- Constant Field Values
-
CLASS_CAST_MSG
private static final java.lang.String CLASS_CAST_MSG
- See Also:
- Constant Field Values
-
-
Method Detail
-
queryToString
public static <T extends java.lang.Enum<T>> java.lang.String queryToString(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiQuery<T> query)
Translate a WmiQuery to the actual query string- Type Parameters:
T
- WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.- Parameters:
query
- The WmiQuery object- Returns:
- The string that is queried in WMI
-
getString
public static <T extends java.lang.Enum<T>> java.lang.String getString(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a String value from a WmiResult- Type Parameters:
T
- WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.- Parameters:
result
- The WmiResult from which to fetch the valueproperty
- The property (column) to fetchindex
- The index (row) to fetch- Returns:
- The stored value if non-null, an empty-string otherwise
-
getDateString
public static <T extends java.lang.Enum<T>> java.lang.String getDateString(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Date value from a WmiResult as a String in ISO 8601 format- Type Parameters:
T
- WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.- Parameters:
result
- The WmiResult from which to fetch the valueproperty
- The property (column) to fetchindex
- The index (row) to fetch- Returns:
- The stored value if non-null, an empty-string otherwise
-
getDateTime
public static <T extends java.lang.Enum<T>> java.time.OffsetDateTime getDateTime(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a DateTime value from a WmiResult as an OffsetDateTime- Type Parameters:
T
- WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.- Parameters:
result
- The WmiResult from which to fetch the valueproperty
- The property (column) to fetchindex
- The index (row) to fetch- Returns:
- The stored value if non-null, otherwise the constant
Constants.UNIX_EPOCH
-
getRefString
public static <T extends java.lang.Enum<T>> java.lang.String getRefString(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Reference value from a WmiResult as a String- Type Parameters:
T
- WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.- Parameters:
result
- The WmiResult from which to fetch the valueproperty
- The property (column) to fetchindex
- The index (row) to fetch- Returns:
- The stored value if non-null, an empty-string otherwise
-
getStr
private static <T extends java.lang.Enum<T>> java.lang.String getStr(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
-
getUint64
public static <T extends java.lang.Enum<T>> long getUint64(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Uint64 value from a WmiResult (parsing the String). Note that while the CIM type is unsigned, the return type is signed and the parsing will exclude any return values above Long.MAX_VALUE.- Type Parameters:
T
- WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.- Parameters:
result
- The WmiResult from which to fetch the valueproperty
- The property (column) to fetchindex
- The index (row) to fetch- Returns:
- The stored value if non-null and parseable as a long, 0 otherwise
-
getUint32
public static <T extends java.lang.Enum<T>> int getUint32(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets an UINT32 value from a WmiResult. Note that while a UINT32 CIM type is unsigned, the return type is signed and requires further processing by the user if unsigned values are desired.- Type Parameters:
T
- WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.- Parameters:
result
- The WmiResult from which to fetch the valueproperty
- The property (column) to fetchindex
- The index (row) to fetch- Returns:
- The stored value if non-null, 0 otherwise
-
getUint32asLong
public static <T extends java.lang.Enum<T>> long getUint32asLong(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets an UINT32 value from a WmiResult as a long, preserving the unsignedness.- Type Parameters:
T
- WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.- Parameters:
result
- The WmiResult from which to fetch the valueproperty
- The property (column) to fetchindex
- The index (row) to fetch- Returns:
- The stored value if non-null, 0 otherwise
-
getSint32
public static <T extends java.lang.Enum<T>> int getSint32(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Sint32 value from a WmiResult. Note that while the CIM type is unsigned, the return type is signed and requires further processing by the user if unsigned values are desired.- Type Parameters:
T
- WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.- Parameters:
result
- The WmiResult from which to fetch the valueproperty
- The property (column) to fetchindex
- The index (row) to fetch- Returns:
- The stored value if non-null, 0 otherwise
-
getUint16
public static <T extends java.lang.Enum<T>> int getUint16(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Uint16 value from a WmiResult. Note that while the CIM type is unsigned, the return type is signed and requires further processing by the user if unsigned values are desired.- Type Parameters:
T
- WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.- Parameters:
result
- The WmiResult from which to fetch the valueproperty
- The property (column) to fetchindex
- The index (row) to fetch- Returns:
- The stored value if non-null, 0 otherwise
-
getInt
private static <T extends java.lang.Enum<T>> int getInt(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
-
getFloat
public static <T extends java.lang.Enum<T>> float getFloat(com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult<T> result, T property, int index)
Gets a Float value from a WmiResult- Type Parameters:
T
- WMI queries use an Enum to identify the fields to query, and use the enum values as keys to retrieve the results.- Parameters:
result
- The WmiResult from which to fetch the valueproperty
- The property (column) to fetchindex
- The index (row) to fetch- Returns:
- The stored value if non-null, 0 otherwise
-
-