VB.NET中获取串口列表

Imports Microsoft.Win32

Private Sub GetComList()

Dim keycom As RegistryKey = Registry.LocalMachine.OpenSubKey("Hardware""DeviceMap""SerialComm")

Dim str As String

If Not keycom Is Nothing Then

Dim sSubKeys() As String = keycom.GetValueNames()

cmbItem.clear()

For Each str In sSubKeys

Dim s As String = keycom.GetValue(str).ToString.Trim

Me.cmbPLC.Items.Add(s)

cmbitem.add(s)

Next

End If

End Sub