I have used the loop method for years. Here is part of my code.
comstring is defined as a 2 dimensional string array of the ports so that comstring[1]="COM1",comstring[2]=COM2", thru "COM32". portarray[ ] is an integer array, size 33. When the loop is done portarray[x] will contain 1 if COMx exists on the PC, 0 if it does not.
for(i=1;i<33;i++)
{
comstatus=OpenComConfig (i, comstring[i], 9600, 0, 8, 1, 512, 512);
if (comstatus!=0)
{
//FAILED
portarray[i]=0;
}
else
{
//OPENED
portarray[i]=1;
}
CloseCom(i);
}