Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Using IWbemObjectSink with J-Interop

Help
stalidec
2009-09-30
2013-09-10
  • stalidec
    stalidec
    2009-09-30

    Hi,

    I'm now trying to receive events notification from Hyper-V.

    Can I use the "IWbemObjectSink Interface" with J-Interop ?
    Or should I use the JILocalCoClass ?

    Thanks for your help.

    Best regards.

    Seb.

     
  • Hi,
         You will have to use both, i.e implement IWbemObjectSink using JILocalCoClass.

    Just when you do, please post :) …

    best regards,
    Vikram

     
  • Hi,
         You will have to use both, i.e implement IWbemObjectSink using JILocalCoClass.

    Just when you do, please post :) …

    best regards,
    Vikram

     
    • Mike J
      Mike J
      2013-09-10

      it is interesting to see how an IWbemObjectSink interface is implemented. Note: IWbemObjectSink is an interface defined in the COM API for WMI (c++), while j-interop is based on the Scripting API for WMI(vb script). There is no a counterpart of IWbemObjectSink in Scripting API for WMI. Can you do it? There is a SWbemSink object which has no methods, indicate() and setStatus().

       
  • stalidec
    stalidec
    2009-10-01

    Ok, thanks.

    But before doing that i need to copy a file with the Win32_Directory Class.

    I have an exception (0x80020009) on the wbemObjectSet_dispatch.get("Count"), do you see what's wrong on my code ?

    thanks, best regards,
    Seb.

        session = JISession.createSession(args,args,args);
        session.useSessionSecurity(true);
        comStub = new JIComServer(JIProgId.valueOf("WbemScripting.SWbemLocator"),address,session);
        comServer = comStub.createInstance();
        comObject = (IJIComObject)comServer.queryInterface("76A6415B-CB41-11d1-8B02-00600806D9B6");//ISWbemLocator
        dispatch = (IJIDispatch)JIObjectFactory.narrowObject(comObject.queryInterface(IJIDispatch.IID));

        JIVariant results = dispatch.callMethodA("ConnectServer",new Object{new JIString(address),new JIString("ROOT\\CIMV2"),JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), new Integer(0), JIVariant.OPTIONAL_PARAM()});

        wbemServices_dispatch = (IJIDispatch)JIObjectFactory.narrowObject((results).getObjectAsComObject());

        JIVariant results2 = wbemServices_dispatch.callMethodA("ExecQuery", new Object{new JIString("SELECT * FROM Win32_Directory WHERE Name = 'c:\\documents and settings'"), new JIString("WQL"), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM()});
        IJIDispatch wbemObjectSet_dispatch = (IJIDispatch)JIObjectFactory.narrowObject((results2).getObjectAsComObject());

        JIVariant variant = wbemObjectSet_dispatch.get("_NewEnum");
        IJIComObject object2 = variant.getObjectAsComObject();

        IJIEnumVariant enumVARIANT = (IJIEnumVariant)JIObjectFactory.narrowObject(object2.queryInterface(IJIEnumVariant.IID));

        JIVariant Count = wbemObjectSet_dispatch.get("Count");
        int count = Count.getObjectAsInt();
        for (int i = 0; i < count; i++)
    {
    Object values = enumVARIANT.next(1);

    JIArray array = (JIArray)values;
    Object arrayObj = (Object)array.getArrayInstance();
    for (int j = 0; j < arrayObj.length; j++)
    {
    IJIDispatch wbemObject_dispatch = (IJIDispatch)JIObjectFactory.narrowObject(((JIVariant)arrayObj).getObjectAsComObject());
    JIVariant variant2 = (JIVariant)(wbemObject_dispatch.callMethodA("GetObjectText_",new Object{new Integer(1)}));
    System.out.println(variant2.getObjectAsString().getString());
    System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
    }
    }

     
  • stalidec
    stalidec
    2009-10-01

    I found the mistake, my query is incorrect. I should now find how to write it.

     
  • scottley
    scottley
    2009-10-01

    also… as an aside on dealing with the WbemObjectSet that gets returned, don't rely on the "Count" property.  If you are setting up your connection in semi-synchronous or asynchronous modes (using the return immediately flag and/or the forward only flag) as suggested by the MSDN, then you will throw an exception when you ask for the "Count".  what I do to parse the returned Enum is just infinite loop over the enum.next(1) and break on the 0x00000001 error code which signifies that you just walked off the end of your enum.

     
  • stalidec
    stalidec
    2009-10-01

    Thx for the hint Scottley.

    I found that the path should be like this "c:\\\\\\\\documents and settings", so now i can get the Win32_Directory of a folder, but i can't for a file…

     
  • stalidec
    stalidec
    2009-10-01

    ok with CIM_DataFile it works better…