Class WmiUtil

java.lang.Object
oshi.util.platform.windows.WmiUtil

@ThreadSafe public final class WmiUtil extends Object
Helper class for WMI
  • Field Details

    • OHM_NAMESPACE

      public static final 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:
    • LHM_NAMESPACE

      public static final String LHM_NAMESPACE
      The namespace where LibreHardwareMonitor publishes to WMI, LHM_NAMESPACE="ROOT\\LibreHardwareMonitor". This namespace is not built-in to WMI, so if LHM is not running would result in unnecessary log messages.
      See Also:
  • Method Details

    • queryToString

      public static <T extends Enum<T>> String queryToString(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 Enum<T>> String getString(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 value
      property - The property (column) to fetch
      index - The index (row) to fetch
      Returns:
      The stored value if non-null, an empty-string otherwise
    • getDateString

      public static <T extends Enum<T>> String getDateString(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 value
      property - The property (column) to fetch
      index - The index (row) to fetch
      Returns:
      The stored value if non-null, an empty-string otherwise
    • getDateTime

      public static <T extends Enum<T>> OffsetDateTime getDateTime(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 value
      property - The property (column) to fetch
      index - The index (row) to fetch
      Returns:
      The stored value if non-null, otherwise the constant Constants.UNIX_EPOCH
    • getRefString

      public static <T extends Enum<T>> String getRefString(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 value
      property - The property (column) to fetch
      index - The index (row) to fetch
      Returns:
      The stored value if non-null, an empty-string otherwise
    • getUint64

      public static <T extends Enum<T>> long getUint64(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 value
      property - The property (column) to fetch
      index - The index (row) to fetch
      Returns:
      The stored value if non-null and parseable as a long, 0 otherwise
    • getUint32

      public static <T extends Enum<T>> int getUint32(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 value
      property - The property (column) to fetch
      index - The index (row) to fetch
      Returns:
      The stored value if non-null, 0 otherwise
    • getUint32asLong

      public static <T extends Enum<T>> long getUint32asLong(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 value
      property - The property (column) to fetch
      index - The index (row) to fetch
      Returns:
      The stored value if non-null, 0 otherwise
    • getSint32

      public static <T extends Enum<T>> int getSint32(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 value
      property - The property (column) to fetch
      index - The index (row) to fetch
      Returns:
      The stored value if non-null, 0 otherwise
    • getUint16

      public static <T extends Enum<T>> int getUint16(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 value
      property - The property (column) to fetch
      index - The index (row) to fetch
      Returns:
      The stored value if non-null, 0 otherwise
    • getFloat

      public static <T extends Enum<T>> float getFloat(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 value
      property - The property (column) to fetch
      index - The index (row) to fetch
      Returns:
      The stored value if non-null, 0 otherwise