2013-02-19 114 views
1

我的應用程序需要在使用java的計算機上列出所有可用的還原點(Link)。 SystemRestore類在CIMV2中的默認名稱空間中找到。當我嘗試下面的代碼:Jacob - 檢索系統還原信息(Java)

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 

請幫助。

回答

0

在這裏,我們有一個職位,說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調用)。