[英]How to get what's using the COM Port Visual Basic (.NET)
I have this code here 我这里有这段代码
For i As Integer = 0 to My.Computer.Ports.SerialNames.Count - 1
ComboBox1.Items.Add(My.Computer.Ports.SerialPortNames(i))
Next
Example Output: 示例输出:
COM1
COM2
COM3
this returns a list of used COM ports in a ComboBox 这将在ComboBox中返回使用的COM端口的列表
now what I want to do is something like this 现在我想做的就是这样
COM1 <USB Mouse>
COM2 <USB Keyboard>
etc. 等等
I want to get whatever it is using the COM port. 我想使用COM端口获取任何信息。
Hope anyone can help, thanks! 希望任何人都能帮助,谢谢!
Here I found a link where your question is solved: Msdn forum 在这里,我找到了一个可以解决您问题的链接: MSDN论坛
It uses Windows Management Instrumentation to retrieve the data you want from the ports. 它使用Windows Management Instrumentation从端口检索所需的数据。 This way you will retrieve the full name of the port, including the part you want.
这样,您将检索端口的全名,包括所需的部分。
Here is the code: 这是代码:
' Add reference to System.Management.dll.
Try
Dim searcher As New ManagementObjectSearcher( _
"root\cimv2", _
"SELECT * FROM Win32_SerialPort")
For Each queryObj As ManagementObject In searcher.Get()
MsgBox(queryObj("Name"))
Next
Catch err As ManagementException
MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
End Try
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.