How to access information in Windows Device Manager from Java?

java, winapi, windows

Solution

I am looking at Java Native Access as it provides access to the windows API from pure Java code - no JNI to deal with. I was concerned about the LGPL license; whether it can be included in a commercial product but from what a few posts in the newsgroup say, it can be. After I try it out in the next few weeks, I shall post back here.

Problem

I have a serial to USB device and more than one of those can be connected to the computer. I need to query and retrieve a list of COM ports that the devices are connected to. In Windows Device Manager you can get the COM port + friendly name of devices that are connected at the present time. This list is dynamic. Reading from the registry did not work because the information stored is stale and static, not dynamic. Devcon (from Microsoft) does list the ports that devices are connected to, but it cannot be used in my app because it is not re-distributable. Any ideas or preferably, a solution?

Original source

Related problems