I am using JACOB to access system information through WMI. I have not found much documentation for WMI and Jacob on the web and was wondering if I could get some help in making the code a little more efficient.
Here is the code:
String query = "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name='_Total'";
Variant vCollection = mActiveXWMI.invoke("ExecQuery", new Variant(query));
EnumVariant enumVariant = new EnumVariant(vCollection.toDispatch());
Dispatch item = null;
while (enumVariant.hasMoreElements()) {
item = enumVariant.nextElement().toDispatch();
cpuUsage = Double.parseDouble(Dispatch.call(item, "PercentProcessorTime").toString());
}
As one can see, it doesn't seem to make much sense of looping through a collection for just one item. I would like to just query for one column in the query statement and get the result from that as quickly and efficiently as possible, with as little overhead as possible.
Does anyone have much experience with JACOB and retrieving these values in the best way possible?
Thanks,
Steve