com.hp.ucmdb.discovery.library.clients.query
Class WMIClient

java.lang.Object
  extended by com.hp.ucmdb.discovery.library.clients.BaseClient
      extended by com.hp.ucmdb.discovery.library.clients.query.QueryClient
          extended by com.hp.ucmdb.discovery.library.clients.query.WMIClient

public class WMIClient
extends QueryClient

WMIClient provides services for executing queries on WMI databases and the Windows registry. Use this class for protocols whose name is ClientsConsts.WMI_PROTOCOL_NAME
The working namespace to query can be redefined for WmiClient by setting the value of property AgentConstants.PROP_WMI_NAMESPACE. If not set, the default root\\cimv2 is used.
All Protocol properties can be redefined when creating the client.
Here is example of using WMIClient to work with the Windows registry:


 # The method that prepares client for query and calls getRegValues method for execution
 def DiscoveryMain(Framework):
    props = Properties()
    props.setProperty(AgentConstants.PROP_WMI_NAMESPACE, 'root\\DEFAULT')
    wmiClient = Framework.getClientFactory().createClient(props)
    keypath = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
    filter = 'DisplayName'
    names = getRegValues(wmiClient, keypath, filter)

 # This method executes and processes the result
 def getRegValues(wmiClient, keypath, filter):
     result = {}
     table = wmiClient.getRegistryKeyValues(keypath, 1, filter)
     keys = table.get(0)
     values = table.get(1)
     for i in range(keys.size()):
         key = keys.get(i)
         end = key.find('\\' + filter)
         key = key[0:end]
         result.update({key : values.get(i)})
     return result
  

See Also:
QueryClient

Field Summary
 
Fields inherited from class com.hp.ucmdb.discovery.library.clients.BaseClient
CREDENTIALS_ID, ENCODING
 
Constructor Summary
WMIClient(ClientsFrameworkImpl framework, java.util.Properties props)
           
 
Method Summary
 java.util.ArrayList getRegistryKeyValues(java.lang.String keypath, boolean bUseFilter, java.lang.String filter)
          Returns values from the HKEY_LOCAL_MACHINE tree of the Windows registry.
 java.util.ArrayList getRegistryKeyValues(java.lang.String HKEY, java.lang.String keypath, boolean bUseFilter, java.lang.String filter)
          Returns values from the specified tree of the Windows registry.
 
Methods inherited from class com.hp.ucmdb.discovery.library.clients.query.QueryClient
executeQuery
 
Methods inherited from class com.hp.ucmdb.discovery.library.clients.BaseClient
close, getClientType, getCredentialId, getIpAddress, getProperty, getShellCmdSeperator, getSudoCommands, getSudoPaths, getTimeout, getUserName, isConnected, supportsSudo
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WMIClient

public WMIClient(ClientsFrameworkImpl framework,
                 java.util.Properties props)
          throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

getRegistryKeyValues

public java.util.ArrayList getRegistryKeyValues(java.lang.String keypath,
                                                boolean bUseFilter,
                                                java.lang.String filter)
                                         throws java.lang.Exception
Returns values from the HKEY_LOCAL_MACHINE tree of the Windows registry. Returns values under the WMIUtil.HKEY_LOCAL_MACHINE root entry.

Parameters:
keypath - The relative path under HKEY
bUseFilter - If true, only filtered attributes are returned
filter - Specifies which fields will be returned
Returns:
An array of two array elements. The first array element contains the keys. The second contains the corresponding values.
Throws:
java.lang.Exception

getRegistryKeyValues

public java.util.ArrayList getRegistryKeyValues(java.lang.String HKEY,
                                                java.lang.String keypath,
                                                boolean bUseFilter,
                                                java.lang.String filter)
                                         throws java.lang.Exception
Returns values from the specified tree of the Windows registry.

Parameters:
HKEY - The registry root from which to return values
keypath - The relative path under HKEY
bUseFilter - If true, only filtered attributes are returned
filter - Specifies which fields will be returned
Returns:
An array of two array elements. The first array element contains the keys. The second contains the corresponding values.
Throws:
java.lang.Exception


Documentation Feedback
Copyright 2010 Hewlett-Packard Development Company, L.P.