KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wmi > Main


1 package wmi;
2
3 import com4j.Com4jObject;
4
5 /**
6  * Uses Microsoft WMI Scripting Library to access the system information.
7  *
8  * <p>
9  * For more about WMI, see
10  *
11  * <ul>
12  * <li>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/anch_wmi.asp
13  * <li>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/scripting_api_objects.asp
14  * <li>http://www.microsoft.com/downloads/details.aspx?FamilyId=6430F853-1120-48DB-8CC5-F2ABDC3ED314&displaylang=en
15  * </ul>
16  *
17  * <p>
18  * Thanks to Simon Assens for pointing me to WMI.
19  *
20  * @author Kohsuke Kawaguchi
21  */

22 public class Main {
23     public static void main(String JavaDoc[] args) {
24         System.out.println("Connecting to WMI repository");
25         ISWbemLocator wbemLocator = ClassFactory.createSWbemLocator();
26         ISWbemNamedValueSet nvs = ClassFactory.createSWbemNamedValueSet();
27         // connecting to WMI repository
28
ISWbemServices wbemServices = wbemLocator.connectServer("localhost","Root\\CIMv2","","","","",0,nvs);
29         System.out.println("connected");
30
31
32
33         // gathering all 'System' log events
34
System.out.println("Listing logical disks");
35         ISWbemObjectSet result = wbemServices.execQuery("Select * from Win32_LogicalDisk","WQL",16,nvs);
36
37         for( Com4jObject obj : result ) {
38             ISWbemObject wo = obj.queryInterface(ISWbemObject.class);
39             System.out.println(wo.getObjectText_(0));
40 // Object o = wo.properties_().item("Description", 0).value();
41
// System.out.println(o);
42
}
43     }
44 }
45
Popular Tags