Find answers, ask questions, and connect with our
community all around the world.

Home Forum Omnis General Forum Automation Object

  • Automation Object

    Posted by Benjamin Rohner on December 10, 2018 at 3:19 pm

    Hello Omnis Forum
    When working with the Windows automation object I am stopped over the question of how to iterate over collection sets. I wanted to implement the following Windows-Script in Omnis using Automation-Objects:

    ;  sComputerName = "."
    ;  Set objWMIService = GetObject("winmgmts:\\" & sComputerName & "\root\cimv2")
    ;  sQuery = "SELECT * FROM Win32_Process WHERE Name LIKE '%%'"
    ;  Set collectionProcesses = objWMIService.ExecQuery(sQuery)
    ;  For Each objItem In collectionProcesses
    ;  Wscript.Echo objItem.Name
    ;  Next

    What I’ve got so far, which works, is the following code. But there are still 2 questions, see the code below.

    Do lListProcesses.$define(ProcessName)
    Do lobjSWbemLocator.$createobject() ; subtype = .Automation Library.Automation\\WbemScripting.SWbemLocator.1
    Do lobjSWbemLocator.$connectserver(".","root\cimv2") Returns lobjSWbemServices
    Do lobjSWbemServices.$execquery("SELECT * FROM Win32_Process WHERE Name LIKE '%%'") Returns lCollectionProcesses
    Calculate lCountProcesses as lCollectionProcesses.$xcount
    For l1 from 0 to lCountProcesses-1 step 1
        ;  Question 1: Is it possible to iterate through the collection like in the Windows Script example? If so how?
        ;  I helped myself with the Item Index method, but there are not for every collection. E.g. below.
        Do lCollectionProcesses.$itemindex(l1) Returns lObjItem
        ;  Question 2: Is it possible to directly access the property "Name" here? Analogous to the line "echo     objItem.Name" in Windows Script
        ;  Since I didn't get the access via Name-Property yet, I have to get the whole PropertySet object.
        ;  This is quite time consuming, so I would like to save the second part.</strong>
        Calculate lPropertySet as lObjItem.$::properties_
        Do lPropertySet.$item("Name") Returns lPropertyName
        Do lListProcesses.$add(lPropertyName.$::value)
    End For

    I am very grateful for answers.
    Best regards

    Benjamin Rohner replied 5 years, 2 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

Log in to reply.