Package org.metricshub.wmi.wbem
Class WmiWbemServices
java.lang.Object
org.metricshub.wmi.wbem.WmiWbemServices
- All Implemented Interfaces:
AutoCloseable,WindowsRemoteExecutor
Class for WBEM Services handling.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Release the WBEM services, disconnect and remove from the cacheexecuteCommand(String command, String workingDirectory, Charset charset, long timeout) Execute the command on the remoteExecutes the specified method of the specified class on the specified object.executeWql(String wql, long timeout) Execute a WQL query and process its result.executeWql(WqlQuery wqlQuery, long timeout) Execute a WQL query and process its result.com.sun.jna.platform.win32.COM.Wbemcli.IWbemContextGet the hostname.static WmiWbemServicesgetInstance(String networkResource, String username, char[] password) Get a WmiWbemServices instance for the specified networkResource.com.sun.jna.PointerInvoke the IWbemServices::GetObject method.char[]Get the password.Get the username.com.sun.jna.platform.win32.COM.Wbemcli.IWbemLocatorcom.sun.jna.platform.win32.COM.Wbemcli.IWbemServicesbooleanisClosed()voidobjectPut(com.sun.jna.Pointer pWbemClassObject, String propertyName, com.sun.jna.platform.win32.Variant.VARIANT pVal) Invoke the IWbemClassObject::Put method.com.sun.jna.PointerspawnInstance(com.sun.jna.Pointer pWbemClassObject) Invoke the IWbemClassObject::SpawnInstance method.
-
Method Details
-
getInstance
public static WmiWbemServices getInstance(String networkResource, String username, char[] password) throws WmiComException Get a WmiWbemServices instance for the specified networkResource.- Parameters:
networkResource- \\hostname\namespace or just namespace for localhost (mandatory)username- The username name (may be null).password- The password (may be null).- Returns:
- WmiWbemServices instance
- Throws:
WmiComException- For any problem encountered with JNA
-
close
public void close()Release the WBEM services, disconnect and remove from the cache- Specified by:
closein interfaceAutoCloseable
-
executeWql
public List<Map<String,Object>> executeWql(String wql, long timeout) throws TimeoutException, WqlQuerySyntaxException, WmiComException Execute a WQL query and process its result.
Use the IWbemServices pointer to make requests of WMI.
Step 6 from: Example: Getting WMI Data from a Remote Computer
- Specified by:
executeWqlin interfaceWindowsRemoteExecutor- Parameters:
wql- the WQL query (required)timeout- Timeout in milliseconds (throws an IllegalArgumentException if negative or zero)- Returns:
- a list of result rows. A result row is a Map(LinkedHashMap to preserve the query order) of properties/values.
- Throws:
TimeoutException- to notify userName of timeout.WqlQuerySyntaxException- if WQL query syntax is invalidWmiComException- on any COM problem
-
executeWql
public List<Map<String,Object>> executeWql(WqlQuery wqlQuery, long timeout) throws TimeoutException, WmiComException, WqlQuerySyntaxException Execute a WQL query and process its result.
Use the IWbemServices pointer to make requests of WMI.
Step 6 from: Example: Getting WMI Data from a Remote Computer
- Parameters:
wqlQuery- the WQL query (as aWqlQueryinstance)timeout- Timeout in milliseconds (throws an IllegalArgumentException if negative or zero)- Returns:
- a list of result rows. A result row is a Map(LinkedHashMap to preserve the query order) of properties/values.
- Throws:
TimeoutException- to notify userName of timeout.WqlQuerySyntaxException- if WQL query syntax is invalidWmiComException- on any COM problem
-
executeCommand
public WindowsRemoteCommandResult executeCommand(String command, String workingDirectory, Charset charset, long timeout) throws WmiComException, TimeoutException Description copied from interface:WindowsRemoteExecutorExecute the command on the remote- Specified by:
executeCommandin interfaceWindowsRemoteExecutor- Parameters:
command- The command to executeworkingDirectory- Path of the directory for the spawned process on the remote system (can be null)charset- The charsettimeout- Timeout in milliseconds- Returns:
- The command result
- Throws:
TimeoutException- To notify userName of timeout.WmiComException
-
getObject
Invoke the IWbemServices::GetObject method.
The IWbemServices::GetObject method retrieves a class or instance.
- Parameters:
objectPath- Path of the object to retrieve. (mandatory)- Returns:
- A pointer on IWbemClassObject.
- Throws:
WmiComException- For any problem encountered with JNA.- See Also:
-
- IWbemServices::GetObject method (wbemcli.h) Pointer on IWbemServices instance.
-
executeMethod
public Map<String,Object> executeMethod(String objectPath, String className, String methodName, Map<String, Object> inputMap) throws WmiComExceptionExecutes the specified method of the specified class on the specified object. Method inputs are specified as a Map<String, Object> mapping input names with their values.- Parameters:
objectPath- WBEM path to the object on which the method is to be executedclassName- Name of the class where the method is definedmethodName- Name of the method to invokeinputMap- Map of input parameters for the method- Returns:
- a Map<String, Object> with the output parameters of the method
- Throws:
WmiComException- if anything goes wrong
-
objectPut
public void objectPut(com.sun.jna.Pointer pWbemClassObject, String propertyName, com.sun.jna.platform.win32.Variant.VARIANT pVal) throws WmiComException Invoke the IWbemClassObject::Put method.
The IWbemClassObject::Put method sets a named property to a new value.
- Parameters:
pWbemClassObject- A pointer on IWbemClassObject. (mandatory)propertyName- A parameter that must point to a valid property name. (mandatory)pVal- A parameter that must point to a valid VARIANT, which becomes the new property value. If pVal is NULL or points to a VARIANT of type VT_NULL, the property is set to NULL, that is, no value.- Throws:
WmiComException- For any problem encountered with JNA.- See Also:
-
spawnInstance
public com.sun.jna.Pointer spawnInstance(com.sun.jna.Pointer pWbemClassObject) throws WmiComException Invoke the IWbemClassObject::SpawnInstance method.
Use the IWbemClassObject::SpawnInstance method to create a new instance of a class.
- Parameters:
pWbemClassObject- A pointer on IWbemClassObject. (mandatory)- Returns:
- A pointer on instantiated WBEM Class object.
- Throws:
WmiComException- For any problem encountered with JNA.- See Also:
-
getNetworkResource
-
getHostname
Description copied from interface:WindowsRemoteExecutorGet the hostname.- Specified by:
getHostnamein interfaceWindowsRemoteExecutor- Returns:
-
getUsername
Description copied from interface:WindowsRemoteExecutorGet the username.- Specified by:
getUsernamein interfaceWindowsRemoteExecutor- Returns:
-
getPassword
public char[] getPassword()Description copied from interface:WindowsRemoteExecutorGet the password.- Specified by:
getPasswordin interfaceWindowsRemoteExecutor- Returns:
-
getWbemServices
public com.sun.jna.platform.win32.COM.Wbemcli.IWbemServices getWbemServices() -
getWbemLocator
public com.sun.jna.platform.win32.COM.Wbemcli.IWbemLocator getWbemLocator() -
getContext
public com.sun.jna.platform.win32.COM.Wbemcli.IWbemContext getContext() -
getAuthIdent
-
isClosed
public boolean isClosed()
-