-
Automation Object
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. ; https://docs.microsoft.com/en-us/windows/desktop/wmisdk/swbemobjectset-itemindex 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> ; https://docs.microsoft.com/en-us/windows/desktop/wmisdk/swbempropertyset Calculate lPropertySet as lObjItem.$::properties_ ; https://docs.microsoft.com/en-us/windows/desktop/wmisdk/swbempropertyset-item Do lPropertySet.$item("Name") Returns lPropertyName Do lListProcesses.$add(lPropertyName.$::value) End For
I am very grateful for answers.
Best regards
Ben-
This discussion was modified 1 year, 9 months ago by
Bernhard Mairhofer.
-
This discussion was modified 1 year, 9 months ago by
Sorry, there were no replies found.
Log in to reply.