开发者

About use jinterop get windows event log

when i run the code below:

JISession dcomSession = JISession.createSession(domain, user, pass);
dcomSession.useSessionSecurity(false);
JIProgId id =  JIProgId.valueOf("WbemScripting.SWbemLocator");
id.setAutoRegistration(true);
JIComServer wbemLocatorComObj = new JIComServer(id, host,dcomSession);

exception occurs:

开发者_如何学JAVA
    org.jinterop.dcom.common.JIException: Access is denied, please check whether the [domain-username-password] are correct. Also, if not already done please check the GETTING STARTED and FAQ sections in readme.htm. They provide information on how to correctly configure the Windows machine for DCOM access, so as to avoid such exceptions.  [0x00000005]
    at org.jinterop.winreg.smb.JIWinRegStub.winreg_CreateKey(JIWinRegStub.java:310)
    at org.jinterop.dcom.core.JIComServer.initialise(JIComServer.java:510)
    at org.jinterop.dcom.core.JIComServer.<init>(JIComServer.java:414)
    at main.java.EventLogListener.getWmiLocator(EventLogListener.java:43)
    at main.java.EventLogListener.main(EventLogListener.java:87)
Caused by: org.jinterop.dcom.common.JIRuntimeException: Access is denied, please check whether the [domain-username-password] are correct. Also, if not already done please check the GETTING STARTED and FAQ sections in readme.htm. They provide information on how to correctly configure the Windows machine for DCOM access, so as to avoid such exceptions.  [0x00000005]
    at org.jinterop.winreg.IJIWinReg$createKey.read(IJIWinReg.java:459)
    at ndr.NdrObject.decode(NdrObject.java:36)
    at rpc.ConnectionOrientedEndpoint.call(ConnectionOrientedEndpoint.java:137)
    at rpc.Stub.call(Stub.java:113)
    at org.jinterop.winreg.smb.JIWinRegStub.winreg_CreateKey(JIWinRegStub.java:304)
    ... 4 more

I 'm sure the host domian user password is ok, when JIProgId id = JIProgId.valueOf("InternetExplorer.Application"); it works, but why above doesn't work?

Please give me some advice!


Take a look on this code:

import static org.jinterop.dcom.impls.JIObjectFactory.narrowObject;
import static org.jinterop.dcom.impls.automation.IJIDispatch.IID;

JISession dcomSession = JISession.createSession(domain, user, pass);
JIComServer comServer = new JIComServer(valueOf("WbemScripting.SWbemLocator"), hostname, dcomSession);
IJIDispatch wbemLocator = (IJIDispatch) narrowObject(comServer.createInstance().queryInterface(IID));

Object[] params = new Object[] {
        new JIString(hostname),
        new JIString("ROOT\\CIMV2"),
        JIVariant.OPTIONAL_PARAM(),
        JIVariant.OPTIONAL_PARAM(),
        JIVariant.OPTIONAL_PARAM(),
        JIVariant.OPTIONAL_PARAM(),
        new Integer(0),
        JIVariant.OPTIONAL_PARAM()
};
JIVariant results[] = wbemLocator.callMethodA("ConnectServer", params);
IJIDispatch wbemServices = (IJIDispatch) narrowObject(results[0].getObjectAsComObject());

I found it here: http://www.vijaykandy.com/2009/09/windows-management-instrumentation-wmi-from-java/

I think that dcomSession.useSessionSecurity(false); causes your trouble.

So, try the tutorial I referenced. I hope all will work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜