Jacob连接到远程计算机以获取WMI支持 [英] Jacob connect to Remote Computer for WMI support
问题描述
我正在尝试使用java和Jacob连接到远程计算机,以获取有关远程计算机的一些WMI信息.
I'm trying to connect to a remote computer using java and Jacob in order to get some WMI Information about the remote computer.
对于localhost,我正在使用下面的代码,它工作正常.
For localhost I'm using the code below and it works fine.
String host = "localhost";
String connectStr = String.format("winmgmts:\\\\%s\\root\\CIMV2", host);
ActiveXComponent axWMI = new ActiveXComponent(connectStr);
// other code to get system information
但是,如果我将localhost更改为另一个IP/主机名,则会出现以下错误:
But if I change localhost to another ip/hostname I got the following error:
Exception in thread "main" com.jacob.com.ComFailException: Can't find moniker
at com.jacob.com.Dispatch.createInstanceNative(Native Method)
at com.jacob.com.Dispatch.<init>(Dispatch.java:99)
at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58)
at easyticket.classes.WmiExtended.main(WmiExtended.java:28)
引发异常的行是:
ActiveXComponent axWMI = new ActiveXComponent(connectStr);
编辑
我尝试使用WbemScripting
String host = "192.168.7.106";
ActiveXComponent axWMI = new ActiveXComponent("WbemScripting.SWbemLocator");
axWMI.invoke("ConnectServer", new Variant(host+",\"root\\cimv2\",\"username\",\"password\""));
但是我得到了这个错误:
but I got this error:
Exception in thread "main" com.jacob.com.ComFailException: Invoke of: ConnectServer
Source: SWbemLocator
Description: The RPC server is unavailable.
我该如何解决?如何传递用户名/密码,以及是否需要域?
我正在使用Windows 8,并且试图连接到win8/win7/winxp/win2003server计算机.
I'm using Windows 8 and I'm trying to connect to win8/win7/winxp/win2003server computers.
推荐答案
经过一些搜索,我设法解决了我的问题...
After some searches I managed to solve my problem...
这是任何人需要的代码.
Here's the code if anyone need it.
ActiveXComponent wmi = new ActiveXComponent("WbemScripting.SWbemLocator");
Variant variantParameters[] = new Variant[4];
variantParameters[0] = new Variant(_IPADDRESS);
variantParameters[1] = new Variant("root\\cimv2");
variantParameters[2] = new Variant("username");
variantParameters[3] = new Variant("password");
ActiveXComponent axWMI;
try
{
Variant conRet = wmi.invoke("ConnectServer", variantParameters);
axWMI = new ActiveXComponent(conRet.toDispatch());
}catch(ComFailException e)
{
axWMI = null;
}
if (axWMI == null)
return false;
这篇关于Jacob连接到远程计算机以获取WMI支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!