Namaskar Prasad,

You can Get the number of COM ports from Registry key

HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
There is one Value for one COM port
Access Registry.

Thank You

Krishna