How to retrieve swbemobjectset collection from Async call?

Discussion in 'Scripting' started by SeanInSeattle, Oct 9, 2008.

  1. So, does anyone know how to get the collection / swbemobjectset from an
    asynchronous call to WMI on-completed()...? And, also does anyone know how
    to get the collection when its not fully done?

    It seems like it should be possible.... but I'm racking my brain trying to
    find an answer.
     
    SeanInSeattle, Oct 9, 2008
    #1
    1. Advertisements

  2. SeanInSeattle

    urkec Guest


    Here is a sample:


    Set objSWbemServices = GetObject _
    ("winmgmts:\\.\root\cimv2")

    Set objSink = WScript.CreateObject _
    ("WbemScripting.SWbemSink","objSink_")

    objSWbemServices.ExecQueryAsync _
    objSink, "Select * From CIM_DataFile " & _
    "Where Path = '\\windows\\system32\\'"

    MsgBox "Waiting for objects!"


    Sub objSink_OnCompleted(iHRes, objWmiErr, objCntxt)
    WScript.Echo VbCrtLf & "Async call completed."
    End Sub

    Sub objSink_OnObjectReady(objWmiObj, objCntxt)
    WScript.Echo objWmiObj.FileName
    End Sub



    MsgBox prevents the script from ending. objSink_OnObjectReady receives
    CIM_DataFile instances asynchronously (as objWmiObj) and echoes their
    FileName property. When the call is completed objSink_OnCompleted is
    triggered.
    I'm not sure if it is possible to get the collection of WMI objects as a
    SWbemObjectSet object with an asynchronous call.
     
    urkec, Oct 10, 2008
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.