Ну вот такое я использую у себя на васике ,для определения существующих ,точнее доступных на данный момент портов.
обьявляем
Код
Type DCB
DCBlength As Long
BaudRate As Long
fBitFields As Long
wReserved As Integer
XonLim As Integer
XoffLim As Integer
ByteSize As Byte
Parity As Byte
StopBits As Byte
XonChar As Byte
XoffChar As Byte
ErrorChar As Byte
EofChar As Byte
EvtChar As Byte
wReserved1 As Integer
End Type
Type COMMCONFIG
dwSize As Long
wVersion As Integer
wReserved As Integer
dcbx As DCB
dwProviderSubType As Long
dwProviderOffset As Long
dwProviderSize As Long
wcProviderData As Byte
End Type
Declare Function GetDefaultCommConfig Lib "kernel32" _
Alias "GetDefaultCommConfigA" (ByVal lpszName As String, _
lpCC As COMMCONFIG, lpdwSize As Long) As Long
Public Function EnumSerPorts(port As Integer) As Long
'this function returns non-zero value if the port exists
Dim cc As COMMCONFIG, ccsize As Long
'
ccsize = LenB(cc) 'gets the size of COMMCONFIG structure
'
EnumSerPorts = GetDefaultCommConfig("COM" + Trim(Str(port)) + _
Chr(0), cc, ccsize)
'
End Function
определяем ,передаем параметр номер порта ,если существует EnumSerPorts возвращает 1.
Код
If EnumSerPorts(5) = 1 Then menu_port_com5.Enabled = True
If EnumSerPorts(4) = 1 Then menu_port_com4.Enabled = True
If EnumSerPorts(3) = 1 Then menu_port_com3.Enabled = True
If EnumSerPorts(2) = 1 Then menu_port_com2.Enabled = True
If EnumSerPorts(1) = 1 Then menu_port_com1.Enabled = True