1

My app is required to list all available restore points(Link) on a computer using java. The SystemRestore class is found in the default namespace not in CIMV2. When i tried the following code:

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();

        }
    }    
} 

But it end up with the following error:

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

Please help.

nasiroudin
  • 337
  • 3
  • 14

1 Answers1

0

Here we have a post saying this error can be caused by not running as Administrator.

And here is an example where you get the same error by querying the external data WMI alias but should be querying the full name when using select.

SELECT Index,InterfaceIndex,SettingID,IpAddress,ServiceName,Description
FROM NICCONFIG
WHERE IPEnabled=true

It should be:

SELECT Index,InterfaceIndex,SettingID,IpAddress,ServiceName,Description
FROM Win32_NetworkAdapterConfiguration
WHERE IPEnabled=true

Here is a guide for using either the external alias (from commandline) or the full name (from a WMI API call).

memnoch_proxy
  • 1,944
  • 15
  • 20