Sun WBEM SDK Developer's Guide

Example — Getting Instances

The code segment in Example 4–8 lists all processes on a given system. This example uses the enumerateInstanceNames method to get the names of instances of the CIM_Process class. Running this code on a Microsoft Windows 32 system returns Windows 32 processes. Running this same code on a Solaris system returns Solaris processes.


Example 4–8 Getting Instances of a Class (getInstance)

...
{
//Create namespace cns
CIMnameSpace cns = new CIMNameSpace(); 
 
//Connect to the cns namespace on the CIM Object Manager
cc = new CIMClient(cns, "root", "root_password"); 
 
/* Pass the CIM Object Path of the CIM_Process class 
to the CIM Object Manager. We want to get instances of 
this class. */ 
 
CIMObjectPath cop = new CIMObjectPath("CIM_Process"); 
 
/* The CIM Object Manager returns an enumeration of 
object paths, the names of instances of 
the CIM_Process class. */
Enumeration e = cc.enumerateInstanceNames(cop); 
 
/* Iterate through the enumeration of instance object paths.
Use the CIM Client getInstance class to get 
the instances referred to by each object name. */

while(e.hasMoreElements()) {
    CIMObjectPath op = (CIMObjectPath)e.nextElement();
    // Get the instance. Returns only the properties
		// that are local to the instance (localOnly is true).
		CIMInstance ci = cc.getInstance(op, true);
		}
...