How can i get the list of Com ports in machine.

  • Thread starter Thread starter Umut Tezduyar
  • Start date Start date
U

Umut Tezduyar

I want to get the list of com and parallel ports in the machine, is there a
way to do it in the .Net Framework.
 
The current version does not support COM ports from managed code.
If you know the Win32 API calls that are required, you can call these from
..NET using Platform Invoke.


Chris
 
Hi,

The only way that I know is to P/Invoke (Platform Invoke) the Windows32
EnumPorts APIs. There isn't anything in the .NET Framework that provides
this information.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
This might help:

Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_POTSModem")
moReturn = moSearch.Get

For Each mo In moReturn
Debug.WriteLine(mo("Name") & " is attached to " &
mo("AttachedTo"))
Next
 
I tried this and cannot get VB.NET 2003 to work with this. I even find
references to :
Imports System.Management
in the Help files. But, still adding that outside the module in a Console
app. it still generates an error.
(sorry to jump in here but, this looked like an easy way to find the
commports.)
So, I am curious how you are getting this to work.
james
 
I think that Dart makes a nice .Net comm control if you don't feel like messing around with p/invoke.
 
Umm, whoops, I forgot to give credit where credit is due. Sorry. That code
was actually posted by a Mr. Ken Tucker on another Microsoft group (can't
remember where). Apologies, Ken. There's a glitch or two depending on the
OS, apparently.

If you want the full story (AFAIK), check out
http://vbforums.com/showthread.php?s=&threadid=273454

Thanks Ken,
Mike
 
Back
Top