Use the CIMClient deleteClass method to delete a class. Deleting a class removes the class and throws a CIMException.
You must first remove any existing subclasses or instances before deleting a base class.
This example uses the deleteClass method to delete a class in the default namespace root\cimv2. This program takes four required string arguments (hostname, classname, username, and password). The user running this program must specify the username and password for an account that has write permission to the root\cimv2 namespace.
import javax.wbem.cim.CIMClass; import javax.wbem.cim.CIMException; import javax.wbem.cim.CIMNameSpace; import javax.wbem.cim.CIMObjectPath; import javax.wbem.client.CIMClient; import javax.wbem.client.UserPrincipal; import javax.wbem.client.PasswordCredential; import java.rmi.*; import java.util.Enumeration; /** * Deletes the class specified in the command line. Works in the default * namespace root/cimv2. */ public class DeleteClass { public static void main(String args[]) throws CIMException { CIMClient cc = null; // if not four arguments, show usage and exit if (args.length != 4) { System.out.println("Usage: DeleteClass host className " + "username password"); System.exit(1); } try { // args[0] contains the hostname. We create a CIMNameSpace // (cns) pointing to the default namespace on the specified host CIMNameSpace cns = new CIMNameSpace(args[0]); // args[2] and args[3] contain the username and password. // We create a UserPrincipal (up) using the username and // a PasswordCredential using the password. UserPrincipal up = new UserPrincipal(args[2]); PasswordCredential pc = new PasswordCredential(args[3]); cc = new CIMClient(cns, up, pc); // Get the class name (args[4]) and create a CIMObjectPath CIMObjectPath cop = new CIMObjectPath(args[1]); // delete the class cc.deleteClass(cop); } catch (Exception e) { System.out.println("Exception: "+e); } if (cc != null) { cc.close(); } } }