Home > other >  J - Interop connected to the 64 - bit systems WMI information error: Java. Lang. ArrayIndexOutOfBoun
J - Interop connected to the 64 - bit systems WMI information error: Java. Lang. ArrayIndexOutOfBoun

Time:04-30



Business code would only write four years of development, the distributed high concurrency also can't be a programmer? ->>


Package systeminfo. Util;

The import java.net.UnknownHostException;
Import the Java. Util. Logging. Level;

The import org.jinterop.dcom.com mon. JIException;
The import org.jinterop.dcom.com mon. JISystem;
The import org. Jinterop. Dcom. Core. IJIComObject;
The import org. Jinterop. Dcom. Core. JIArray;
The import org. Jinterop. Dcom. Core. JIComServer;
The import org. Jinterop. Dcom. Core. JIProgId;
The import org. Jinterop. Dcom. Core. JISession;
The import org. Jinterop. Dcom. Core. JIString;
The import org. Jinterop. Dcom. Core. JIVariant;
The import org. Jinterop. Dcom. Impls. JIObjectFactory;
The import org. Jinterop. Dcom. Impls. Automation. IJIDispatch;
The import org. Jinterop. Dcom. Impls. Automation. IJIEnumVariant;

Public class WMIUtil {
Private JIComServer m_ComStub=null;
Private IJIComObject m_ComObject=null;
Private IJIDispatch m_Dispatch=null;
Private JISession m_Session=null;
Private IJIDispatch m_WbemServices=null;
Private static final String WMI_CLSID="76 a6415b - CB41-11 d1-8 d9b6 b02-00600806".
Private static final String WMI_PROGID="WbemScripting. SWbemLocator";
Private String m_Host=null;
Private String m_Domain="ROOT \ \ CIMV2";
Private String m_Username;
Private String m_Password;

Public static void main (String [] args) {
WMIUtil wmiService=new WMIUtil (" ", "192.168.9.9", "Administrator", "cloudsino");
WmiService. The connect ();//system information
WmiService. Query (" SELECT * FROM Win32_ComputerSystem ");//CPU information
WmiService. Query (" SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE the Name!='_Total' ");//memory information
WmiService. Query (" SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory ");//disk information
WmiService. Query (" SELECT * FROM Win32_PerfRawData_PerfDisk_PhysicalDisk Where the Name!='_Total' ");
WmiService. Disconnect ();
}

Public WMIUtil (String domain, String host, String username, String password) {
JISystem. SetAutoRegisteration (true);
JISystem. GetLogger (). SetLevel (Level. WARNING);
Enclosing m_Host=host;
Enclosing m_Domain=domain;
Enclosing m_Username=username;
Enclosing m_Password=password;
}

Public void query (String strQuery) {
System. The out. Println (" query: "+ strQuery);
JIVariant results []=new JIVariant [0].
Try {
Results=m_WbemServices. CallMethodA (" ExecQuery ", the new Object [] {
New JIString (strQuery), JIVariant OPTIONAL_PARAM (),
JIVariant. OPTIONAL_PARAM (), JIVariant OPTIONAL_PARAM ()});
IJIDispatch wOSd=(IJIDispatch) JIObjectFactory
NarrowObject ((results [0]) getObjectAsComObject ());
Int count=wOSd. Get (" count "). GetObjectAsInt ();
IJIComObject enumComObject=wOSd. Get (" _NewEnum ")
GetObjectAsComObject ();
IJIEnumVariant enumVariant=(IJIEnumVariant) JIObjectFactory
NarrowObject (enumComObject
. QueryInterface (IJIEnumVariant. IID));
IJIDispatch wbemObject_dispatch=null;
for (int c=0; c Object [] values=enumVariant. Next (1);
JIArray array=(JIArray) values [0].
Object [] arrayObj=(Object []) array. The getArrayInstance ();
for (int j=0; J & lt; ArrayObj. Length; J++) {
WbemObject_dispatch=(IJIDispatch) JIObjectFactory
NarrowObject (((JIVariant) arrayObj [j])
GetObjectAsComObject ());
}
String STR=(wbemObject_dispatch callMethodA (" GetObjectText_, "
The new Object [] {1})) [0]. GetObjectAsString2 ();
System. The out. Println (" (" c + + ") : ");
System. The out. Println (STR);
System.out.println();
}
} the catch (JIException e) {
e.printStackTrace();
}
}

Public void the connect () {
Try {
M_Session=JISession. CreateSession (m_Domain m_Username, m_Password);
M_Session. UseSessionSecurity (false);
M_Session. SetGlobalSocketTimeout (6000);
M_ComStub=new JIComServer (JIProgId. The valueOf (WMI_PROGID), m_Host, m_Session);
IJIComObject unknown=m_ComStub. CreateInstance ();
M_ComObject=unknown. QueryInterface (WMI_CLSID);
M_Dispatch=(IJIDispatch) JIObjectFactory. NarrowObject (m_ComObject
. QueryInterface (IJIDispatch. IID));
JIVariant results []=m_Dispatch. CallMethodA (
"ConnectServer,"
The new Object [] {new JIString (m_Host),
JIVariant. OPTIONAL_PARAM (),
JIVariant. OPTIONAL_PARAM (),
JIVariant. OPTIONAL_PARAM (),
JIVariant. OPTIONAL_PARAM (),
JIVariant. OPTIONAL_PARAM (), and 0,
JIVariant. OPTIONAL_PARAM ()});
M_WbemServices=(IJIDispatch) JIObjectFactory
NarrowObject ((results [0]) getObjectAsComObject ());
} the catch (JIException e) {
e.printStackTrace();
If (m_Session!=null) {
Try {
JISession. DestroySession (m_Session);
{} the catch (JIException e1)
e.printStackTrace();
}
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related