j-Interop调用64位系统的WMI获取信息报错 5C

报如下错误,有没有大神用过,给下解决办法.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 16
at jcifs.util.Encdec.dec_uint32le(Encdec.java:90)
at ndr.NdrBuffer.dec_ndr_long(NdrBuffer.java:146)
at ndr.NetworkDataRepresentation.readUnsignedLong(NetworkDataRepresentation.java:64)
at org.jinterop.dcom.core.JIRemoteSCMActivator$RemoteCreateInstance.read(JIRemoteSCMActivator.java:642)
at ndr.NdrObject.decode(NdrObject.java:36)
at rpc.ConnectionOrientedEndpoint.call(ConnectionOrientedEndpoint.java:137)
at rpc.Stub.call(Stub.java:113)
at org.jinterop.dcom.core.JIComServer.init(JIComServer.java:645)
at org.jinterop.dcom.core.JIComServer.initialise(JIComServer.java:496)
at org.jinterop.dcom.core.JIComServer.(JIComServer.java:429)
at systeminfo.util.WMIUtil.connect(WMIUtil.java:93)
at systeminfo.util.WMIUtil.main(WMIUtil.java:35)

package systeminfo.util;

import java.net.UnknownHostException;
import java.util.logging.Level;

import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.common.JISystem;
import org.jinterop.dcom.core.IJIComObject;
import org.jinterop.dcom.core.JIArray;
import org.jinterop.dcom.core.JIComServer;
import org.jinterop.dcom.core.JIProgId;
import org.jinterop.dcom.core.JISession;
import org.jinterop.dcom.core.JIString;
import org.jinterop.dcom.core.JIVariant;
import org.jinterop.dcom.impls.JIObjectFactory;
import org.jinterop.dcom.impls.automation.IJIDispatch;
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 = "76A6415B-CB41-11d1-8B02-00600806D9B6";
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.connect();// 系统信息
    wmiService.query("SELECT * FROM Win32_ComputerSystem");// CPU信息
    wmiService.query("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name != '_Total'");// 内存信息
    wmiService.query("SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory");// 磁盘信息
    wmiService.query("SELECT * FROM Win32_PerfRawData_PerfDisk_PhysicalDisk Where Name != '_Total'");
    wmiService.disconnect();
}

public WMIUtil(String domain,String host,String username, String password) {
    JISystem.setAutoRegisteration(true);
    JISystem.getLogger().setLevel(Level.WARNING);
    this.m_Host = host;
    this.m_Domain = domain;
    this.m_Username = username;
    this.m_Password = password;
}

public void query(String strQuery) {
    System.out.println("query:" + strQuery);
    JIVariant results[] = new JIVariant[0];
    try {
        results = m_WbemServices.callMethodA("ExecQuery", 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 < count; c++) {
            Object[] values = enumVariant.next(1);
            JIArray array = (JIArray) values[0];
            Object[] arrayObj = (Object[]) array.getArrayInstance();
            for (int j = 0; j < arrayObj.length; j++) {
                wbemObject_dispatch = (IJIDispatch) JIObjectFactory
                        .narrowObject(((JIVariant) arrayObj[j])
                                .getObjectAsComObject());
            }
            String str = (wbemObject_dispatch.callMethodA("GetObjectText_",
                    new Object[] { 1 }))[0].getObjectAsString2();
            System.out.println("(" + c + "):");
            System.out.println(str);
            System.out.println();
        }
    } catch (JIException e) {
        e.printStackTrace();
    }
}

public void 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.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",
                new Object[] { new JIString(m_Host),
                        JIVariant.OPTIONAL_PARAM(),
                        JIVariant.OPTIONAL_PARAM(),
                        JIVariant.OPTIONAL_PARAM(),
                        JIVariant.OPTIONAL_PARAM(),
                        JIVariant.OPTIONAL_PARAM(), 0,
                        JIVariant.OPTIONAL_PARAM() });
        m_WbemServices = (IJIDispatch) JIObjectFactory
                .narrowObject((results[0]).getObjectAsComObject());
    } catch (JIException e) {
        e.printStackTrace();
        if (m_Session != null) {
            try {
                JISession.destroySession(m_Session);
            } catch (JIException e1) {
                e.printStackTrace();
            }
        }
    } catch (UnknownHostException e) {
        if (m_Session != null) {
            try {
                JISession.destroySession(m_Session);
            } catch (JIException e1) {
                e1.printStackTrace();
            }
        }
    }
}

public void disconnect() {
    try {
        JISession.destroySession(m_Session);
    } catch (JIException e) {
        e.printStackTrace();
    }
}

}

2个回答

ArrayIndexOutOfBoundsException
connect函数中有越界。at systeminfo.util.WMIUtil.connect(WMIUtil.java:93) 具体看看哪一个

我觉得是main 函数有问题

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐