title: How to determine a Windows system's maximum COM port number?
body: <p>I have a system which has some devices with which it communicates through virtual COM ports. With time, the COM port numbers change. I made some code that will search for the new COM port numbers for these devices and remember them. This works fine.</p>
  
  <p>My problem is with defining the COM port number search range. I found, <a href="http://support.microsoft.com/kb/100111" rel="noreferrer">in the Microsoft KB</a>, that there is usually (by default) a limit of 256 COM ports on a Windows NT OS. They also specify that this is configurable and there's nothing preventing a system to have a very different maximum COM port number.</p>
  
  <p><strong>I'm wondering if there's a way to programmatically know the COM port number range.</strong> Obviously, if I let the system only search the 2⁸ range, it's going to take a very significantly shorter time than searching the, say, 2¹⁶ range! But if the system running my application is set to support over 2⁸ COM port numbers, at some point the application will surely start failing over and over again, until the COM port number allocation loops back to COM0 (or is it COM1?). I'd like to avoid that, if it doesn't require too much sorcery.</p>
  
  <p>I'm mainly working with Java, but any idea is welcome.</p>