首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jacob连接到远程计算机以支持WMI

Jacob连接到远程计算机以支持WMI
EN

Stack Overflow用户
提问于 2013-07-10 14:30:56
回答 1查看 2.1K关注 0票数 4

我正在尝试使用java和Jacob连接到远程计算机,以获取有关远程计算机的一些WMI信息。

对于localhost,我使用了下面的代码,它运行得很好。

代码语言:javascript
复制
    String host = "localhost";
    String connectStr = String.format("winmgmts:\\\\%s\\root\\CIMV2", host);

    ActiveXComponent axWMI = new ActiveXComponent(connectStr);
    // other code to get system information

但是,如果我将本地主机更改为另一个ip/主机名,则会出现以下错误:

代码语言:javascript
复制
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)

抛出异常的行是:

代码语言:javascript
复制
ActiveXComponent axWMI = new ActiveXComponent(connectStr);

编辑

我尝试使用WbemScripting传递用户名/密码

代码语言:javascript
复制
String host = "192.168.7.106";
ActiveXComponent axWMI = new ActiveXComponent("WbemScripting.SWbemLocator");
axWMI.invoke("ConnectServer", new Variant(host+",\"root\\cimv2\",\"username\",\"password\""));

但我发现了一个错误:

代码语言:javascript
复制
Exception in thread "main" com.jacob.com.ComFailException: Invoke of: ConnectServer
Source: SWbemLocator
Description: The RPC server is unavailable. 

我怎么能解决它?我如何传递用户名/密码,如果需要,域?

我正在使用Windows 8,并试图连接到win7 8/win7 7/winxp/win7 2003服务器计算机。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-18 09:44:31

经过一番搜索,我终于解决了我的问题.

这是密码,如果有人需要的话。

代码语言:javascript
复制
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;
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17573374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档