I'm trying to connect to a remote computer using java and Jacob in order to get some WMI Information about the remote computer.
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
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)
and the row that throws the exception is:
ActiveXComponent axWMI = new ActiveXComponent(connectStr);
EDIT
I tried passing username/password using 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.
How can I solve it? How can I pass username/password and if is needed the domain???
I'm using Windows 8 and I'm trying to connect to win8/win7/winxp/win2003server computers.