Yo tengo instalado el Visual Basic 2005 Express Edition, que es de descarga gratuita desde la web de Microsoft.
Tuve instalado el VB6.0 y la verdad es que el nuevo le da unas pocas vueltas, así que te recomiendo te actualices.
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public Const FILE_SHARE_READ = &H1
Public Const FILE_SHARE_WRITE = &H2
Public Const OPEN_EXISTING = 3
Public Const FILE_ATTRIBUTE_NORMAL = &H80
'// Retorna TRUE si el puerto existe o esta disponible, FAlse en otro caso
Public Function COMAvailable(COMNum As Integer) As Boolean
Dim hCOM As Long
Dim ret As Long
Dim sec As SECURITY_ATTRIBUTES
hCOM = CreateFile("\.\COM" & COMNum & "", 0, FILE_SHARE_READ + _
FILE_SHARE_WRITE, sec, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
If hCOM = -1 Then
COMAvailable = False
Else
COMAvailable = True
ret = CloseHandle(hCOM)
End If
End Function
For i = 1 To 16
If COMAvailable(i) Then
cboComm.AddItem "COMM" & i
End If
Next
'Programa que indica que puertos hay disponibles en la pc
Public i As Integer 'hace el rastreo de puertos
'------------------------------------------------------------------------------
'Variables y funciones usadas para detectar disponibilidad de puertos COM
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
'Entrega True si el puerto está disponible y False en caso contrario
Private Function COMAvailable(COMNum As Integer) As Boolean
Dim hCOM As Long
Dim ret As Long
Dim sec As SECURITY_ATTRIBUTES
hCOM = CreateFile("\.\COM" & COMNum & "", 0, &H1 + _
&H2, sec, 3, &H80, 0)
If hCOM = -1 Then
COMAvailable = False
Else
COMAvailable = True
ret = CloseHandle(hCOM)
End If
End Function
'------------------------------------------------------------------------------
Private Sub Command1_Click()
Combo1.Clear 'limpia combo1
For i = 1 To 16 'busca del com1 al com16 (MSCOMM vb6 solo admite hasta 16)
If COMAvailable(i) Then 'checa puerto por puerto
Combo1.AddItem "COM " & i 'si existe lo agrega a la lista
End If
Next
End Sub