当我运行以下代码时:
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);
发生异常:
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
我确定主机domian用户密码没问题,当它JIProgId id = JIProgId.valueOf("InternetExplorer.Application");
有效时,但为什么以上不起作用?
请给我一些建议!
答案 0 :(得分:0)
看看这段代码:
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());
我在这里找到了它:http://www.vijaykandy.com/2009/09/windows-management-instrumentation-wmi-from-java/
我认为dcomSession.useSessionSecurity(false);
会给您带来麻烦。
所以,试试我引用的教程。我希望一切顺利。