The code segment in Example 6-6 lists all processes on a given system. This example uses the enumInstances 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.
{
//Create namespace cns
CIMnameSpace cns = new CIMNameSpace;
//Connect to the cns namespace on the CIM Object Manager
cc = new CIMClient(cns);
/* Pass the CIM Object Path of the CIM_Process class
to the CIM Object Manager. We want to get instances of this class. */
CIMObjectPath op = new CIMObjectPath("CIM_Process");
/* The CIM Object Manager returns a vector of object paths, the names
of instances of the CIM_Process class. */
Vector v = cc.enumInstances(op, true);
/* Iterate through the vector of instance object paths.
Use the CIM Client getInstance interface to get
the instances referred to by each object name. */
for (int i=0; i < v.size(); i++) {
// Get the instance
CIMInstance ci = cc.getInstance(v.elementAt(i));
/* Get the process ID string for each instance of
CIM_Process. */
CIMProperty cp = ci.getProperty("Handle");
}
|