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
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.
Hope anyone can help, thanks!
Here I found a link where your question is solved: Msdn forum
It uses Windows Management Instrumentation to retrieve the data you want from the ports. 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.