我的应用程序需要使用 java 列出计算机上的所有可用还原点 ( Link )。 SystemRestore 类位于默认命名空间中,而不是 CIMV2 中。当我尝试以下代码时:
public class TestWMI {
public static void main(String args[]){
String host = "localhost";
String connectStr = String.format("winmgmts:\\\\%s\\root\\default", host);
String query = "SELECT * FROM SystemRestore";
ActiveXComponent axWMI = new ActiveXComponent(connectStr);
Variant vCollection = axWMI.invoke("ExecQuery", new Variant(query));
EnumVariant enumVariant = new EnumVariant(vCollection.toDispatch());
Dispatch item = null;
while (enumVariant.hasMoreElements()) {
item = enumVariant.nextElement().toDispatch();
String serviceName = Dispatch.call(item,"Description").toString();
System.out.println();
}
}
}
但最终出现以下错误:
Exception in thread "main" com.jacob.com.ComFailException: IEnumVARIANT::Next
at com.jacob.com.EnumVariant.Next(Native Method)
at com.jacob.com.EnumVariant.hasMoreElements(EnumVariant.java:68)
at TestWMI.main(TestWMI.java:28)
Java Result: 1
请帮忙。
最佳答案
这里我们有一篇文章说 this error can be caused不以管理员身份运行。
下面是一个示例,您通过查询外部数据 WMI 别名得到相同的错误,但在使用 select
时应该查询全名。
SELECT Index,InterfaceIndex,SettingID,IpAddress,ServiceName,Description
FROM NICCONFIG
WHERE IPEnabled=true
应该是:
SELECT Index,InterfaceIndex,SettingID,IpAddress,ServiceName,Description
FROM Win32_NetworkAdapterConfiguration
WHERE IPEnabled=true
这是一个guide for using外部别名(来自命令行)或全名(来自 WMI API 调用)。
关于java - Jacob - 检索系统恢复信息 (Java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14964752/