我正在尝试使用 java 和 Jacob 连接到远程计算机,以便获取有关远程计算机的一些 WMI 信息。
对于本地主机,我使用下面的代码,它工作正常。
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/主机名,则会出现以下错误:
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);
EDIT
我尝试使用传递用户名/密码WbemScripting
String host = "192.168.7.106";
ActiveXComponent axWMI = new ActiveXComponent("WbemScripting.SWbemLocator");
axWMI.invoke("ConnectServer", new Variant(host+",\"root\\cimv2\",\"username\",\"password\""));
但我得到了这个错误:
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 计算机。