WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: Thekub on February 11, 2019, 07:31:29 AM

Title: ForEach Loop Issue - 2019A
Post by: Thekub on February 11, 2019, 07:31:29 AM
We run some code to manage Microsoft SCCM Collections, this code has been in use for several years.  Below is an excerpt, the behavior being seen is the ForEach loop appears to go into an infinite loop (or at least as long as we could stand to allow it to run). 

My co-worker downloaded and installed 2019A on 2/8/19 and got this behavior when running directly or running from a complied EXE.  The same .WBT I can run or compile and the code works as expected, I downloaded and installed 2019A on 1/22/19.  To rule out some issue with his upgrade he installed the same 2019A on a test system that has never had WB installed and the issue persisted.  He rolled back to one of the 2018 releases and the code returned to working order. 

Did the 2019A installer change between those ~2 weeks by chance?  Otherwise, I'm at a bit of a loss to explain this behavior.

objWMISCCMLocator = ObjectOpen("WbemScripting.SWbemLocator")
objWMISCCMServices = objWMISCCMLocator.ConnectServer("<servername>","root\sms\site_<site>",SrvAccount,SrvPassword)

InstCollection = objWMISCCMServices.Get("SMS_Collection.CollectionID='%SCCMCollectionID%'")

ForEach Rule in InstCollection.CollectionRules
If StrUpper(Rule.RuleName) == StrUpper(PCNameSelection)
ExistingRule = @TRUE
EndIf
Next
Title: Re: ForEach Loop Issue - 2019A
Post by: td on February 11, 2019, 07:50:18 AM
The download for WinBatch+Compiler has not changed in any way since its release on January 9, 2019.  Any difference you are seeing is the result of some difference or change to the computer system and not the WinBatch+Compiler download.

The implementation of the ForEach loop was changed for 2019A to fix a rather obscure, never reported by a user bug and improve performance.  It is possible that we introduced a new bug in the processes.  Because the foreach loop was extensively tested before the release and your problem seems to be system dependent, it may be difficult to identify.  However, we will certainly investigate.   
Title: Re: ForEach Loop Issue - 2019A
Post by: td on February 11, 2019, 08:52:32 AM
The following change to your script may help narrow down the problems and may even be a workaround.  So if you are so inclined, please give it a try and report back.

Change this line:
Code (winbatch) Select
ForEach Rule in InstCollection.CollectionRules

to these lines:
Code (winbatch) Select
aRules =  InstCollection.CollectionRules
ForEach Rule in aRules
Title: Re: ForEach Loop Issue - 2019A
Post by: Thekub on February 11, 2019, 09:54:25 AM
My system didn't exhibit the behavior last Friday, so I installed 2019A on a spare laptop and couldn't reproduce the issue on that device.  Ill try and get my co-worker to re-upgrade his system back to 2019A and give this a shot if the behavior manifests again. 
Title: Re: ForEach Loop Issue - 2019A
Post by: Thekub on February 11, 2019, 10:21:07 AM
Jumped the gun on my original observation, I was able to reproduce on my test system as well confirmed the same behavior after my co-worker reinstalled 2019A.

In both cases the suggested modification caused the loop to end normally.  Likewise reverting back to the original layout caused the issue to return.
Title: Re: ForEach Loop Issue - 2019A
Post by: td on February 11, 2019, 11:17:50 AM
The problem's source has been identified.  More testing needs to be done but the problem appears to be confined to collections of type COM Automation variant array.  The ObjectTypeGet function returns the type "ARRAY" for a variable of the type.

We should have a fix in the next release but for now, you will have to rely on the workaround solution.   We apologize for any inconvenience this may have caused and thank you for reporting the problem.