リモート コンピューターに関する WMI 情報を取得するために、java と Jacob を使用してリモート コンピューターに接続しようとしています。
localhost の場合、以下のコードを使用していますが、正常に動作します。
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/hostname に変更すると、次のエラーが発生しました。
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\""));
しかし、私はこのエラーが発生しました:
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 コンピューターに接続しようとしています。