I currently have the below code, but obviously I am not that skilled on working with collections. Hence I cannot seem to work out how to get each name value, out of the rule property, in each round of the loop.
dim c,ExistingRules
set objFWP = createobject("HNetCfg.FwPolicy2")
set colRules = objFWP.rules
for c = 1 to colRules.count - 1
ExistingRules = ExistingRules & colRules(c).name
next
In place of colRules(c).name, I have tried things like:
colRules.item(c).namecolRules.name(c)t = colRules.name / t(c)
… etc
Despite researching how to iterate through a collection without for…each on the web, and learn more about how to work with collections, I am sure that the community here could help me out with a solution/sources to learn more quickly.
The
Rulesobject is an instance of the COM interfaceINetFwRules. As it turns out, there is no way to retrieve an item from this collection by index. The definition of theItemmethodshows that it retrieves the rule by name. So in this particular case, you must use
For Each ... In.If you want to break the loop early and then re-enumerate, you need to reassign the rules collection: