1 package org.jinterop.dcom.test; 2 3 import java.net.UnknownHostException ; 4 5 import org.jinterop.dcom.common.JIException; 6 import org.jinterop.dcom.common.JIInterfaceDefinition; 7 import org.jinterop.dcom.common.JIJavaCoClass; 8 import org.jinterop.dcom.common.JIMethodDescriptor; 9 import org.jinterop.dcom.common.JISystem; 10 import org.jinterop.dcom.core.IJIComObject; 11 import org.jinterop.dcom.core.JIComServer; 12 import org.jinterop.dcom.core.JIInterfacePointer; 13 import org.jinterop.dcom.core.JIProgId; 14 import org.jinterop.dcom.core.JISession; 15 import org.jinterop.dcom.win32.ComFactory; 16 import org.jinterop.dcom.win32.IJIDispatch; 17 18 public class MSSysInfo { 19 20 JISession session = null; 21 IJIComObject sysInfoObject = null; 22 IJIComObject sysInfoServer = null; 23 IJIDispatch dispatch = null; 24 String identifier = null; 25 MSSysInfo(String [] args) throws JIException, UnknownHostException 26 { 27 session = JISession.createSession(args[1],args[2],args[3]); 28 JIComServer comServer = new JIComServer(JIProgId.valueOf(session,"SYSINFO.SysInfo"),args[0],session); 29 sysInfoServer = comServer.createInstance(); 30 sysInfoObject = (IJIComObject)sysInfoServer.queryInterface("6FBA474C-43AC-11CE-9A0E-00AA0062BB4C"); 31 dispatch = (IJIDispatch)ComFactory.createCOMInstance(IJIDispatch.IID,sysInfoObject); 32 33 } 34 void displayValues() throws JIException 35 { 36 System.out.println("ACStatus: " + dispatch.get("ACStatus").getObjectAsShort()); 37 System.out.println("BatteryFullTime: " + dispatch.get("BatteryFullTime").getObjectAsInt()); 38 System.out.println("BatteryLifePercent: " + dispatch.get("BatteryLifePercent").getObjectAsShort()); 39 System.out.println("BatteryLifeTime: " + dispatch.get("BatteryLifeTime").getObjectAsInt()); 40 System.out.println("BatteryStatus: " + dispatch.get("BatteryStatus").getObjectAsShort()); 41 System.out.println("OSVersion: " + dispatch.get("OSVersion").getObjectAsFloat()); 42 44 } 45 46 void AttachEventListener() throws JIException 47 { 48 50 JIJavaCoClass javaComponent = new JIJavaCoClass(new JIInterfaceDefinition("6FBA474D-43AC-11CE-9A0E-00AA0062BB4C"),SysInfoEvents.class); 51 javaComponent.getInterfaceDefinition().addMethodDescriptor(new JIMethodDescriptor("PowerStatusChanged",8,null)); 52 javaComponent.getInterfaceDefinition().addMethodDescriptor(new JIMethodDescriptor("TimeChanged",3,null)); 53 identifier = ComFactory.attachEventHandler(sysInfoServer,"6FBA474D-43AC-11CE-9A0E-00AA0062BB4C",JIInterfacePointer.getInterfacePointer(session,javaComponent)); 54 try { 55 Thread.sleep(3000); 56 } catch (InterruptedException e) { 57 e.printStackTrace(); 59 } } 61 62 void DetachEventListener() throws JIException 63 { 64 ComFactory.detachEventHandler(sysInfoServer,identifier); 65 JISession.destroySession(dispatch.getAssociatedSession()); 66 } 67 68 public static void main(String [] args) { 69 try{ 70 if (args.length < 4) 71 { 72 System.out.println("Please provide address domain username password"); 73 return; 74 } 75 JISystem.setAutoRegisteration(true); 76 MSSysInfo sysInfo = new MSSysInfo(args); 77 sysInfo.displayValues(); 78 sysInfo.AttachEventListener(); 79 Thread.sleep(60000); sysInfo.DetachEventListener(); 81 }catch(Exception e) 82 { 83 e.printStackTrace(); 84 } 85 86 } 87 88 89 } 90 91 | Popular Tags |