SWbemObject as OLEObject

Hi all,

Based on a great thread entitled “Shell Issue” 7 months ago (posted by Eric Brown), and in particular the response from John Hansen, I put together the following code to obtain all of the instances of a Win32_Process:

[code]dim params1(2) As Variant
dim params2(1) As Variant
params1(2) = “root\CIMV2”
params2(1) = “Win32_Process”

dim locator,services,objProcess,processSet,currProcess As OLEObject
locator = new OLEObject(“WbemScripting.SWbemlocator”,true)
services = locator.Invoke(“ConnectServer”,params1)
objProcess = services.Invoke(“Get”,params2)
processSet = objProcess.Invoke(“Instances_”)
dim processCount As Integer = processSet.Invoke(“Count”)

for i = 0 to processCount-1
currProcess = processSet.Item(i) //-----------------> OLEException here: Exception code 0: Generic failure, (failed on “Item”)
//do stuff with currProcess

It works until I get to the third last line of the code where I try to get the individual instances in the collection of processes.

Can anyone help me figure out how to get past this exception?

Ok I just found what I was doing wrong. It needed to be:

for i = 0 to processCount-1
  currProcess = processSet.ItemIndex(i)
  //do stuff with currProcess