How to access information in Windows Device Manager from Java?

时光总嘲笑我的痴心妄想 提交于 2021-02-08 12:41:26

问题


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?


回答1:


I had to solve a similar issue just some weeks ago. I came accross the Jawin-Project that provided everything you need to use WMI-Queries. It is already quite old but works like a charm if you follow the documentation. A nice German walkthrough can be found codegods blog.

For me, it did not solve all problems (I had some very specific things to find out about the target device), I finally created an own JNI (Java Native Interface) Class and DLL in C incorporating the windows API.

I hope this is what you searched for.




回答2:


Did you try this jUSB API or This example ?

I hope this will help you.




回答3:


Use JNA (https://github.com/twall/jna) and take a look at the following page. It might be a useful point to start from.

http://www.digitalinferno.com/wiki/Wiki.jsp?page=JNAPrintDevices




回答4:


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.



来源:https://stackoverflow.com/questions/15372303/how-to-access-information-in-windows-device-manager-from-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!