How to detect installed COM port on PC using VB 2005

C

cmdolcet69

How can I detect that I may have com port (s) installed on my PC....
when I launch my vb application I want to be able to search on my
machine to see how many com ports are valid.
 
C

cmdolcet69

How can I detect that I may have com port (s)  installed on my PC....
when I launch my vb application I want to be able to search on my
machine to see how many com ports are valid.

Nevermind there is a great property in the new serial control called
getportnames() I just called that....
 
D

Dick Grier

In addition, it can be useful to get the port description(s). For this, you
would use System.Management. I provide examples in some detail for this in
my book (see below). Here is an excerpt.

Imports System.Management

Public ReadOnly Property PortDescriptions() As Array

Get

Dim PortDescriptionArray() As String = {}

Dim I As Integer

Dim pReturn As Management.ManagementObjectCollection

Dim pSearch As Management.ManagementObjectSearcher

Dim pObject As Management.ManagementObject

Dim sStatus As String = ""

pSearch = New Management.ManagementObjectSearcher("Select *from
Win32_PnPEntity")

pReturn = pSearch.Get

Try

For Each pObject In pReturn

If InStr(pObject("Name").ToString, "(COM") <> 0 Then

ReDim Preserve PortDescriptionArray(I)

PortDescriptionArray(I) = (pObject("Name").ToString)

I += 1

End If

Next

Catch ex As Exception

End Try

Return PortDescriptionArray

End Get

End Property


Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top